C初入
单词计数
#include<stdio.h>
#define IN 1
#define OUT 0
int main()
{
int c,n1,nw,nc,state;
n1= nw = nc = 0;
state = OUT;
while ((c = getchar()) != EOF)
{
++nc;
if (c == '\n')
++n1;
if (c == ' ' || c == '\t' || c == '\n')
state = OUT;
else if (state == OUT)
{
state = IN;
++nw;
}
}
printf("%d %d %d\n", n1, nw, nc);
/*printf("Hel\blo,World!\n");*/
}
请教个问题:此处"EOF" 输入方式为CTRL-Z,为什么在第一行结尾处输入ctrl+z后没有终止程序,而需要在到下一行后才能终止?且在第一行结尾输入之后进行回车(不应该有个"\n"吗),得到之后的行数为零?