[C]simple code of count input lines,words,chars
2015-06-04 23:55
288 查看
This is a simple C program which can count input lines, words and chars. But the number of words are not very strict. It likes simple
wccommand.
#include<stdio.h> /* 简单的统计行数,单词数目,字符个数等 my_wc.c by orangleliu */ int main() { int c, nl, nw, nc, flag; nl = nw = nc =0; while((c = getchar()) != EOF) { ++nc; if( c == '\n' ) ++nl; if( c == ' '|| c == '\t' || c == '\n') flag = 1; else if ( flag == 1){ ++nw; flag = 0; } } printf("line %d words %d chars %d \n", nl, nw, nc); }
res
lzz-rmbp|file # cat my_wc.c|./a.out line 25 words 68 chars 447
相关文章推荐
- Summary Day30
- Android 数据库打包随APK发布
- Two Sum的快排暴力解法
- Swift—初始 (1)
- 1到N中“1”出现的次数
- php浮点数精确运算
- Android 开发中,如何将 SQLite 和 APK 一起打包发布
- iOS: 剪裁UIImage部分不规则区域
- CRF的库资源
- stack, deque 和 queue的对比
- [SGU495] Kids and Prizes (概率dp)
- Lycn 2013 with SQL AlwaysOn 「一」建立AlwaysOn
- C语言之断言
- Java NIO系列教程(七) FileChannel
- [3]_人人都是产品经理
- yaf 路由协议配置测试
- 实验三 敏捷开发和XP实验
- php BC高精确度函数库
- [转载]js删除几种方式
- ANDROID开发:将数据库文件与项目包一起打包成APK文件