Posted: 12/10/2013 12:17:26 PM EDT
|
I know how to declare character variables and I know I can combine two text strings using " // ".
'CAT' // 'FISH' becomes 'CATFISH' But how do I handle indefinite lists of character strings? Assume a file contains the list of three character strings: THIS IS A TEST OF THE EMERGENCY BROADCAST SYSTEM. If I want the character variable COMBINE to be 'THIS IS A TESTOF THE EMERGENCYBROADCAST SYSTEM', how do I program it? Remember please that the next file the program processes might have 25 or whatever lines of text. I'm paraphrasing here, but I've tried..... 10 read(100,*,end=11) COUNT = COUNT + 1 go to 10 11 rewind 100 do 12 I=1,COUNT read(100,*)LINE(I) COMBINE=COMBINE // LINE(I) 12 continue ...but it doesn't work. Thanks. |
|
FUCK YOU FORTRAN!!!!!!!!!!!!!!!!!!
OP - Good luck on your project When I was in school I was required to take fortran. The prof sucked; told us most would fail. I searched out a tutor and couldn't find one. Went to the dean to ask if he knew of one, he asked "we still teach fortran?" I said "apparently." He asked "why?" He was not much help. I resorted to memorizing and regurgitating pages of code from the book on the exam. I passed with a D. My only D in college and I was damn glad to get it. The prof was right, 85% withdrew or failed. |
|
Make a loop that reads a line then tests for file EOF
It'll be file length independent. http://gcc.gnu.org/onlinedocs/gfortran/IS_005fIOSTAT_005fEND.html |
|
Quoted:
I know how to declare character variables and I know I can combine two text strings using " // ". 'CAT' // 'FISH' becomes 'CATFISH' But how do I handle indefinite lists of character strings? Assume a file contains the list of three character strings: THIS IS A TEST OF THE EMERGENCY BROADCAST SYSTEM. If I want the character variable COMBINE to be 'THIS IS A TESTOF THE EMERGENCYBROADCAST SYSTEM', how do I program it? Remember please that the next file the program processes might have 25 or whatever lines of text. I'm paraphrasing here, but I've tried..... 10 read(100,*,end=11) COUNT = COUNT + 1 go to 10 11 rewind 100 do 12 I=1,COUNT read(100,*)LINE(I) COMBINE=COMBINE // LINE(I) 12 continue ...but it doesn't work. Thanks. Fortran gave me some of the worst headaches I've ever had. When I took it we used IBM punch cards.
Yeah it was a long time ago and I'm an old fart. You have my sympathies sir but that won't help you much. In any case, good luck. |
|
I thought FORTRAN was pretty easy, but I was AE so they kept it pretty simple for us. Although, I did have one program fail. I even say down with the prof and went through it character by character... it was functionally identical to his, he couldn't find anything wrong with it, but it wouldn't compile. ![]() Still aced the class.
|
|
Quoted:
I thought FORTRAN was pretty easy, but I was AE so they kept it pretty simple for us. Although, I did have one program fail. I even say down with the prof and went through it character by character... it was functionally identical to his, he couldn't find anything wrong with it, but it wouldn't compile.
Still aced the class. Same problem for me. Went to a peer and the teacher and they couldn't find the problem either. I got zero on the project and a C instead of an A. |
|
Quoted:
I know how to declare character variables and I know I can combine two text strings using " // ". 'CAT' // 'FISH' becomes 'CATFISH' But how do I handle indefinite lists of character strings? Assume a file contains the list of three character strings: THIS IS A TEST OF THE EMERGENCY BROADCAST SYSTEM. If I want the character variable COMBINE to be 'THIS IS A TESTOF THE EMERGENCYBROADCAST SYSTEM', how do I program it? Remember please that the next file the program processes might have 25 or whatever lines of text. I'm paraphrasing here, but I've tried..... 10 read(100,*,end=11) COUNT = COUNT + 1 go to 10 11 rewind 100 do 12 I=1,COUNT read(100,*)LINE(I) COMBINE=COMBINE // LINE(I) 12 continue ...but it doesn't work. Thanks. It's been 30 years, but the combining of strings is called CONCATENATION. The // is the concatenation operator Google "Fortran Concatenation" may produce some examples. |