home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16396 < prev    next >
Encoding:
Text File  |  1992-11-12  |  1.7 KB  |  51 lines

  1. Path: sparky!uunet!ornl!utkcs2!darwin.sura.net!zaphod.mps.ohio-state.edu!uwm.edu!ux1.cso.uiuc.edu!bert.eecs.uic.edu!uicvm.uic.edu!u17868
  2. Organization: University of Illinois at Chicago
  3. Date: Wednesday, 11 Nov 1992 21:32:38 CST
  4. From: <U17868@uicvm.uic.edu>
  5. Message-ID: <92316.213238U17868@uicvm.uic.edu>
  6. Newsgroups: comp.lang.c
  7. Subject: problem with foef()
  8. Lines: 41
  9.  
  10. i
  11. I am reading a binary file with fread. The file has only two records each of si
  12. ze 193 bytes. The problem is that after reading the second record (structure) t
  13. he feof function does not detects the end of file and goes through the loop one
  14.  more time (third time). I check with the ftell fucntion the position of the
  15. file_pointer (pointer to the file that I am reading). First time it gives the p
  16. osition at 193 i.e after reading the first record. Second time it shows the pos
  17. ition of the file_pointer at 386 which is correct. Now, I don't have any more r
  18. ecords in the file. But, it goes again and reads the same last record again. Th
  19. e position of the file_pointer is still 386. After reading the same record, feo
  20. f detects the end of file and returns.  any suggestions
  21. thanks in advance
  22. u17868@uicvm.cc.uic.edu
  23. sikander
  24.  my program is listed below
  25.  
  26. #include "header.h"
  27. void dispdail(date)
  28. char date[9];
  29. {
  30. int i,j, a;
  31. FILE *file_pointer;
  32. struct activity temp;
  33.  file_pointer = fopen("activity.dat","rb");
  34.  fseek(file_pointer,0,0);
  35.  
  36.        while(!feof(file_pointer))
  37.   {
  38.     fread(&temp, sizeof(temp),1,file_pointer);
  39.     j = strcmp(date,temp.date);
  40.     if(j == 0)
  41.         printf("%s",temp.date);
  42.  
  43.      if(a = (feof(file_pointer)) != 0)
  44.         {
  45.          fclose(file_pointer);
  46.          return;
  47.         }
  48.   }/* end while */
  49.  
  50. }   /* end dispdail */
  51.