Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading lines of text from file

Status
Not open for further replies.

Samohtvii

Programmer
Aug 2, 2012
21
0
0
AU
Hi all just wondering how to get a line of text into a character string.
What i have now gets the first word but I want the whole line

character*50 data
open (7, FILE = 'animals')
read (7, *) data
print *, data



thanks
 
Try
Code:
read(7, '(A)') data
 
Thanks that works perfect.
How would I go about reading until a ":" is found?
and does fortran have an if(!eof) if not end of file statement i can use?
Sorry but I am just starting and am having a bit of trouble.

Thanks
 
Say you have the following
Code:
The five boxing
Wizards jumped: quickly
Squids ink:purple
Do you mean read until the line with Wizards and then to stop
or
if the line contains a colon, to read just Wizards jumped and no further on that line and to skip to the next line. So in the latter case you would get The five boxing Wizards jumped and Squids ink

As for end of file, have a look at how to use IOSTAT
 
Well I have it reading in a whole question with the first (A) that was posted.
The I have some possible answers like Horse:Dog:Cat
So i would get them one by one and add them to a character string array.
Don't have to tell me how to do the whole thing just teach me how to read until a : then do it again until and end of line.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top