“文件结束”是什么意思?意思是C语言?
#include <stdio.h>
main()
{
int c;
while ((c = getchar()) != EOF)
putchar(c);
}
在上面的代码中,哪个字符会打破循环?
我是 C 语言新手,请帮助我。
另外,这个错误是什么意思:codec5.c:8:2:警告:文件末尾没有换行符
#include <stdio.h>
main()
{
int c;
while ((c = getchar()) != EOF)
putchar(c);
}
In the above code, which character will break the loop?
I am new to C, please help me.
Also, what is it meant by this error:codec5.c:8:2: warning: no newline at end of file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该警告仅意味着您需要在源代码末尾添加一个新行。将光标放在文件中
main()
末尾的最后一个}
处,然后按 Enter 键。如果您不从文件加载,则需要检查特定字符来结束程序。如果将 (
|
)(在 Windows 中为<
)一个文件通过管道传输到程序中,则程序应该结束。如果您的程序名为test.exe
并且输入文件为foo.txt
,请尝试运行test.exe
foo.txt
(确保它们位于同一目录中)。The warning just means that you need to have a new line at the end of your source code. Put your cursor at the last
}
in your file at the end ofmain()
and press enter.You need to check for a specific character to end the program if you are not loading from a file. If you pipe (
|
) (<
in Windows) a file into your program, then the program should end. If your program is namedtest.exe
and your input file isfoo.txt
, try runningtest.exe < foo.txt
(make sure they are in the same directory).通过在文件末尾添加换行符(将光标放在
}
后面并按 Enter 键)可以解决该错误。我认为 Ctrl+Z 会破坏循环,但我对此不确定。
The error is solved by putting a newline at the end of the file (put the cursor behind the
}
and press enter).I think the loop is broken with Ctrl+Z, but I'm not sure about that.
它是
stdio.h
中定义的一个特殊常量,表示文件结尾。听起来你的文件末尾没有
\n
:)It is a special constant defined in
stdio.h
which means the end of the file.Sounds like you don't have a
\n
at the end of your file :)