I'm writing a program to read data and store it to file. However I am a bit confused by the EOF statement, and how to get my program to stop reading when there is no more data to read.
My code looks like this
while((c=fgetc(fin2))!=EOF) {
if(c=='#'){
while((c=fgetc(fin2))!='\n'){
}}
else{
ungetc(c,fin2);
fscanf(fin2, "%lf\t %lf\t %lf\t %lf\t %lf)\n", &V2[j], &T2[j], &N4, &N5, &N6);
fprintf(fout2, "%d %lf %lf\n",j, V2[j], T2[j]);
if(T2[j]>MaxT2){
MaxT2=T2[j];
MaxV2=V2[j];
}
++j;
}
}
However, it prints an extra line of "nans"
Any help would be amazing
thank you