#include<stdio.h>
#define IN 1
#define OUT 0
int main()
{
int c;
int nCharCount = 0,nWordsCount = 0, nLinesCount = 0;
int state = OUT;
while(1)
{
while((c =getchar()) != EOF)
{
nCharCount++;
if(c == '\n')
{
nLinesCount++;
}
else if(c == ' ' || c == '\t' || c == ' ')
{
state = OUT;
}
else if(state == OUT)
{
state = IN;
nWordsCount++;
}
}
printf("字符數:%d 單詞數:%d 行數:%d\n",nCharCount, nWordsCount, nLinesCount);
nCharCount = 0;nWordsCount = 0;nLinesCount = 0; state = OUT;
}
return 0;
}
用一個whlie(1)死循環不斷輸入。
程序中若存在錯誤最可能的輸入是些特殊的輸入: