开发者

fgets dont return NULL when no new line found

well i'm using while loop:

while(fgets(pclientRow, 1024 , f) != NULL)

in other classes it works ok, but in o开发者_开发问答ne 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?


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.


You could catch the \n issue by placing something like this in your while loop.

if((int)strlen(pclientRow) == 1) break;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜