word counting

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

posted on 2012-05-19 22:33 三少_爷 阅读(243) 评论(0)  编辑 收藏 引用 所属分类: the c programming language


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

常用链接

留言簿

随笔分类

随笔档案

My Website

搜索

最新评论

阅读排行榜

评论排行榜