当没有找到新行时,fgets 不返回 NULL
好吧,我正在使用 while 循环:
while(fgets(pclientRow, 1024, f) != NULL)
在其他类中它工作正常,但在其中一个类中,当我从 逐行文件,即使行结束它也不会退出循环,我在调试器中看到了这一点。
这是为什么呢?它甚至在以前的班级中也能发挥作用,现在我不知道为什么它不断带来 空行直到它崩溃..
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
标准 ANSI C 函数中的 fgets,请参阅文档:
这里 fgets 读取最大值。到下一个 '\n' 或 EOF 为止有 1023 个字符。
您的行长度超过 1023 个字符,或者最后一行没有终止换行符。
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.
您可以通过在 while 循环中放置类似的内容来捕获 \n 问题。
if((int)strlen(pclientRow) == 1)
休息;
You could catch the \n issue by placing something like this in your while loop.
if((int)strlen(pclientRow) == 1)
break;