c - feof() detecting end of file one line before actual end -


this question has answer here:

i have function should read file , detect when file ends.

the function reads second last line , ends. can please tell me i'm doing wrong can't see myself:

int readin(tincan* incan, int toggle)   {   int ii, isfinished = 0;   char fullname[20];   sprintf(fullname, "label_%d.txt", incan->pid);    file* fp;      fp = fopen(fullname, "r");      if(fp==null)        {       printf("error: not open %s\n", fullname);       }      else       {       (ii=0; ii < ((incan->ac)-1); ii++)         {         fscanf(fp, "%*d %*d %*d\n"); /*move through lines without scanning*/         }       fscanf(fp,"%d %d %d", &incan->ac, &incan->state, &incan->time);       }      if (feof(fp) && (toggle == 1))        {       printf("file ended");        writelog(incan);       isfinished = 1;       terminated++;       }    fclose(fp);   return finished;   } 

i expect program have loop in similar to:

while (!feof(fp)) { ...     fscanf(fp, "%*d %*d %*d\n"); ... } 

if want detect when file ends.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -