#: 7796 S3/Languages
27-Oct-90 11:04:16
Sb: #C loop
Fm: Jay Truesdale 72176,3565
To: all
This short OSK C program fragment prints the last structure record twice!
Since the check in the while loop is at the start of the loop I'd figure that
EOF ought to be detected properly. I checked the file using dump and the
last record is only in the file once.
Any ideas??
main()
{
struct example_record record;
FILE *in_file;
while( feof(in_file)==0 )
{
fread(&record, sizeof(record), 1, in_file);
printf("%9d %25s %25s %15s %5s %5d\n", record.ssn, record.name,
record.addr, record.city, record.state, record.zip);
} /* end of while */
fclose(in_file);
} /* End of main */
There are 2 Replies.
|