Candidate simplification
Have not found the source of the issue, but recommended this to simplify debugging. This takes care of PC line endings, excessive manipulation of the file pointer, unneeded limitation of %7lf
and provides better error checking.
FILE *infile_ptr = fopen("c:\\LumaGem\\orbit.txt", "rt"); // PC text file
char buf[1000];
while (fgets(buf, sizeof(buf), infile_ptr)) { // separate I/O from scanning
int count = sscanf(buf,"%lf%lf%lf%lf%lf%lf%lf%lf", &r, &s1, &s2, &e1, &e2, &e3, &d, &f);
if (count != 8) { // check for correct scan count
; //handle error;
}
}
if (ferror(infile_ptr)) {
; //handle error;
}
fclose(infile_ptr);
[Edit] OP posted original text file.
Also add this line to the loop to take care of trailing lines consisting of only spaces.
if (count <= 0) continue;
[Edit] Conclusion.
The use of fseek()
and ftell()
, usually used with binary files, not needed here IMHO, is a Window's bug reading a UNIX text file (\n
) opened in Windows in binary mode "r"
and using fscanf()
which works best reading text files open "rt"
. Nothing found to point to line 123 or its neighbors as a problem area.