开发者

What does "end of file" mean in C?

#include <stdio.h>
main()
{
    int c;
    while ((开发者_如何学Pythonc = 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


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 of main() 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 named test.exe and your input file is foo.txt, try running test.exe < foo.txt (make sure they are in the same directory).


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.


It is a special constant defined in stdio.h which means the end of the file.

codec5.c:8:2: warning: no newline at end of file

Sounds like you don't have a \n at the end of your file :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜