学习之路-练习题参考答案 1-11

#include
#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)死循环不断输入。

程序中若存在错误最可能的输入是些特殊的输入:

你可能感兴趣的:(C)