1

I am trying to scan file by using while loop:

while(feof(src_file) == 0){

}

This method works perfectly fine if there is only one row in scanned file. Otherwise, I get an endless loop. Why is that and how to fix this issue?

  • Please show the entire code you are using to read the file, otherwise we can't help you :) – Binayaka Chakraborty May 25 '13 at 19:34
  • `feof` probably doesn't work like you want it to. – Carl Norum May 25 '13 at 19:35
  • How can it be a duplicate, since this is different problem? Code is tricky to understand and very unclean, sorry about that: (http://s16.postimg.org/3xp95ndhh/image.png) (code is too long to post it here) –  May 25 '13 at 19:38
  • 1
    You are calling `fsetpos`, and that's most probably the source of the problem. Try debugging your program step-by-step. P.S. If the code is too long, please use PasteBin or anything like it. – nullptr May 25 '13 at 19:44

2 Answers2

2

http://www.cplusplus.com/reference/cstdio/feof/ as this says the error is cleared by some api calls a better check is fgetc(src_file) != EOF

frugal-one
  • 901
  • 7
  • 2
1

feof() is used to help determine the cause of the last read error. It returns "true" if the last read error was due to the file having reached the end.

If there wasn't a previous read error, calling feof() is kinda meaningless.

pmg
  • 106,608
  • 13
  • 126
  • 198