单词计数

 1 #include<stdio.h>
 2 #define WrdIn 1
 3 #define WrdOut 0
 4 main()
 5 {
 6     int c,nl,nw,nc,state;
 7     state=WrdOut;
 8     nl=nw=nc=0;
 9     while ( (c=getchar()) !=EOF)
10     {
11         ++nc;
12         if(c=='\n')
13             ++nl;
14         if(c==' ' || c=='\n' || c== '\t')
15             state = WrdOut;
16         else if (state == WrdOut){
17             state = WrdIn;
18             ++nw;
19         }
20     }
21     printf("%d %d %d\n",nl,nw,nc);
22 }

 

posted @ 2014-01-04 00:52  ASMLearner  阅读(186)  评论(0编辑  收藏  举报