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
wc
command.
#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