判断单词个数

代码
1 #include <stdio.h>
2  #define IN 1 /*在单词内*/
3 #define OUT 0 /*在单词外*/
4 main()
5 {
6 int c,nl,nw,nc,state;
7 state=OUT;
8 nl=nw=nc=0;
9 while((c=getchar())!=EOF)
10 {
11 ++nc;
12 if(c=='\n')
13 {
14 ++nl;
15 }
16 if(c==' '||c=='\n'||c=='\t')
17 {
18 state=OUT;
19 }
20 else
21 {
22 if(state==OUT)
23 {
24 state=IN;
25 ++nw;
26
27 }
28
29 }
30 }
31 printf("%d %d %d",nl,nw,nc);
32 }
33

 

posted @ 2011-01-17 10:40  ebusi2010  阅读(221)  评论(0编辑  收藏  举报