- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I opened a (binary) file for Unformatted Direct Read (I'm not using BINARY), and everything is fine, except that the last record is read twice. Why is that? I'm pretty sure my datafile does not have two identical records at the end (I checked with a Hex editor). My code below:
do while (errcode == 0)
read (10, rec=recnum, iostat=errcode) a,b,c
recnum = recnum + 1
print '(I6,I5,I1)', a,b,c
end do
The last record, and only the last record, is printed twice. Why?
do while (errcode == 0)
read (10, rec=recnum, iostat=errcode) a,b,c
recnum = recnum + 1
print '(I6,I5,I1)', a,b,c
end do
The last record, and only the last record, is printed twice. Why?
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's not read twice (per your title), but it is printed twice, because you don't test errcode before printing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ahhhh, I see! I'm just so used to that loop idiom (from other languages) to read from files, and to count on it to stop at EOF. Of course, since we're reading fixed records, the EOF won't be hit until *after* the last record. Thanks Steve!

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page