我一直在尝试getchar(),putchar()并且一直在尝试使用EOF. 下面是我一直在试验的代码片段。
#include
int main(void)
{
int c;
c = getchar();
while(c != EOF)
{
putchar(c);
printf("\n");
printf("%d\n", EOF);
c = getchar();
}
return 0;
}
输入: -
一个
预期输出:-
一个//Due to putchar()
-1//Value of EOF
//Now the cursor should come in next line and wait for next character.
实时输出:-
一个
-1
-1
//Cursor waiting for next character.
我无法理解输出显示-1两次的原因。