I am writing a C code to read floating point numbers from a text file. The text file looks like this:
202.75 47.22 141.20
202.75 47.22 -303.96
202.75 47.22 -301.67
202.75 47.22 482.42
...
There are 19973 lines in this file and the C code snippet that reads the text file is
nLinesToRead = 19973;
x = (float *)calloc(nLinesToRead, sizeof(float));
y = (float *)calloc(nLinesToRead, sizeof(float));
z = (float *)calloc(nLinesToRead, sizeof(float));
ptr = fopen(fileName, "r");
for(i=0; i<nLinesToRead; i++) {
status = fscanf(ptr, "%f%f%f", &x[i], &y[i], &z[i]);
if(feof(ptr) && i<nLinesToRead)
printf("\nERROR: encountered unexpected EOF in line %d", i+1);
if(status != 3) {
printf("\nERROR: Error reading valid pixels from the disk at line %d with status %d and %d\n", i+1, status, feof(ptr));
printf("\nEOF is %d\n", EOF);
exit(FAILURE);
}
}
The output of this code is
ERROR: encountered unexpected EOF in line 19940
ERROR: encountered unexpected EOF in line 19941
ERROR: Error reading valid pixels from the disk at line 19941 with status -1 and 0
indicating that fscanf is encountering EOF at an unexpected location. Looking at lines 19939 through 19942
202.21 47.23 -453.42
202.21 47.23 -445.81
202.21 47.23 -419.89
202.21 47.41 179.25
I don't see anything weird there.
Has anyone encountered this before?