有关EOF的
这是一个统计字符的程序
程序代码:#include <stdio.h>
int main()
{
char c;
int letter, space, digit, other;
printf("Input: \n");
letter = 0; space = 0; digit = 0; other = 0;
while ((c = getchar()) != EOF) //没怎么理解
{
if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
letter++;
else if (c == ' ')
space++;
else if ('0' <= c && c <= '9')
digit++;
else
other++;
}
printf("Output:\n");
printf("%d %d %d %d\n", letter, space, digit, other);
return 0;
}
本来EOF在的地方是\n,该成EOF后,
比如输入12345
返回的是
0 0 0 0
要是输入12345再回车一下
返回的是
0 0 5 1
当然结束是ctrl+c的,
难道没有回车12345就没有输入进去?
不太明白哎~
[此贴子已经被作者于2016-1-22 18:16编辑过]

