C语言中的EOF是什么? [英] What is EOF in the C programming language?
问题描述
你如何看到最后一张照片?换句话说,要为 EOF 输入什么?我检查了定义,它说 EOF 是 -1.
How do you get to see the last print? In other words what to put in for EOF? I checked the definitions and it says EOF is -1.
如果您输入 Ctrl-D,您将看不到任何内容.
And if you enter Ctrl-D you won't see anything.
#include <stdio.h>
int main() {
int c;
while((c = getchar() != EOF)) {
printf("%d
", c);
}
printf("%d - at EOF
", c);
}
推荐答案
在 Linux 系统和 OS X 上,输入导致 EOF 的字符是 Ctrl-D.对于 Windows,它是 Ctrl-Z.
On Linux systems and OS X, the character to input to cause an EOF is Ctrl-D. For Windows, it's Ctrl-Z.
取决于操作系统,此字符仅在它是一行的第一个字符时才有效,即 Enter 之后的第一个字符.由于控制台输入通常是面向行的,系统也可能无法识别 EOF 字符,直到您用 Enter 跟进它之后.
Depending on the operating system, this character will only work if it's the first character on a line, i.e. the first character after an Enter. Since console input is often line-oriented, the system may also not recognize the EOF character until after you've followed it up with an Enter.
是的,如果该字符被识别为 EOF,那么您的程序将永远不会看到实际的字符.相反,C 程序将从 getchar()
获得 -1
.
And yes, if that character is recognized as an EOF, then your program will never see the actual character. Instead, a C program will get a -1
from getchar()
.
这篇关于C语言中的EOF是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!