当没有找到新行时,fgets 不返回 NULL

发布于 2024-10-05 06:11:13 字数 242 浏览 0 评论 0原文

好吧,我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暗藏城府 2024-10-12 06:11:13

标准 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.

小瓶盖 2024-10-12 06:11:13

您可以通过在 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;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文