home *** CD-ROM | disk | FTP | other *** search
- 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
- Organization: University of Illinois at Chicago
- Date: Wednesday, 11 Nov 1992 21:32:38 CST
- From: <U17868@uicvm.uic.edu>
- Message-ID: <92316.213238U17868@uicvm.uic.edu>
- Newsgroups: comp.lang.c
- Subject: problem with foef()
- Lines: 41
-
- i
- I am reading a binary file with fread. The file has only two records each of si
- ze 193 bytes. The problem is that after reading the second record (structure) t
- he feof function does not detects the end of file and goes through the loop one
- more time (third time). I check with the ftell fucntion the position of the
- file_pointer (pointer to the file that I am reading). First time it gives the p
- osition at 193 i.e after reading the first record. Second time it shows the pos
- ition of the file_pointer at 386 which is correct. Now, I don't have any more r
- ecords in the file. But, it goes again and reads the same last record again. Th
- e position of the file_pointer is still 386. After reading the same record, feo
- f detects the end of file and returns. any suggestions
- thanks in advance
- u17868@uicvm.cc.uic.edu
- sikander
- my program is listed below
-
- #include "header.h"
- void dispdail(date)
- char date[9];
- {
- int i,j, a;
- FILE *file_pointer;
- struct activity temp;
- file_pointer = fopen("activity.dat","rb");
- fseek(file_pointer,0,0);
-
- while(!feof(file_pointer))
- {
- fread(&temp, sizeof(temp),1,file_pointer);
- j = strcmp(date,temp.date);
- if(j == 0)
- printf("%s",temp.date);
-
- if(a = (feof(file_pointer)) != 0)
- {
- fclose(file_pointer);
- return;
- }
- }/* end while */
-
- } /* end dispdail */
-