The problem is that you need to do the feof
check immediately after you try to fscanf
, but before you increment your row counter. Otherwise you will increment it for the eof
.
while(1){
fscanf(inStr," %c %f %f %f %f %f %d",&app1, &app2, &app3, &app4, &app5, &app6,&app7);
if (feof(inStr)) break;
valid++;
}
printf("%d",valid);
Of course, you could also do as Martin James suggested and subtract one from the result.