consequences of writing to file handle of a closed file
Posted on 2004-11-09
I had a bug (since fixed), as follows.
out_fp = fopen("RXCOVER.OUT", "wt");
for (file_count = 0; file_count < 4; ++file_count)
fp = open_file(fn[file_count], "rb+");
for each record in the file fp
read a record from fp
if the record meets a certain condition, write a message to
fclose(out_fp); // WRONG!! this fclose() belongs outside the
} // for file_count
So, after the first iteration of the loop, out_fp was CLOSED,
yet I was still trying to write data to it.
Is it possible that since it was closed, that (bad) data could
have been written to fp??
Reason I ask is that a few records in fp became trashed. When I looked to see what program I might have run at the time the datafile was last modified (17:06, 11/6/04), this program was
indeed run at that time.