TIP: Click on subject to list as thread! ANSI
echo: cis.languages
to: all
from: Jay Truesdale 72176,3565
date: 1990-10-27 11:04:16
subject: #C loop

#: 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.

SOURCE: compuserve via textfiles.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.