fgets dont return NULL when no new line found
-
29-09-2019 - |
Question
well i'm using while loop:
while(fgets(pclientRow, 1024 , f) != NULL)
in other classes it works ok, but in one of them, when i'm reading from file line by line, it won't get out of the loop even when the lines end, i saw that in the debugger.
why is it? and it was working even in that class before and now i dont know why it keep bringing empty lines untill it's crshing..
any idea?
Solution
fgets in a standard ANSI C function, see documentation: Here fgets read max. 1023 character up to next '\n' or EOF. Your lines are longer than 1023 character or the last line has no terminating newline.
OTHER TIPS
You could catch the \n issue by placing something like this in your while loop.
if((int)strlen(pclientRow) == 1) break;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow