Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Position pointer in I/O

Status
Not open for further replies.

xj90

Civil/Environmental
Feb 2, 2012
5
Hi all,

When you read data from a data file (txt file), how can you move the position pointer to the n row of the data (without reading each row again and again)?
For I am writing a program to put the n row of the data into an array, I am currently repeating
read (101,*)
n-1 times to get rid of the data I don't need, but that is inefficient, isn't it?
Thanks in advance.
 
Replies continue below

Recommended for you

If Fortran, those two choices of reading a file are called:

Sequential access, and
Direct access

You may read a bit on it anywhere, here are 3 links.

I personally have not used Direct access much. I usually think of it for reading huge binary files; which I have no need for.

Read the links above carefully, for Direct access apparently the records in the file all need to be of the same length.
 
Why not just use two files. Read from one, write the data you want to the other. When you have finished, delete the original and rename the new file to the original.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor