自己写代码,替代Linux下的WC完成字符数,行数和单词数的统计

字节写代码,替代Linux下的WC完成字符数,行数和单词数的统计

#include
int main()
{
int c,nc,lc,wc,stat;
stat=nc=wc=lc=0;
printf("count is begin(LRQ)/n-------------------------------/n");
while ((c=getchar())!=EOF)
{
        putchar(c);
        ++nc;
        if (c=='/n')
                ++lc;
        if (c==' '||c=='/n'||c=='/t')
           stat=0;
        else if (stat==0)
                {
                        stat=1;
                        ++wc;
                }
}
printf("/n-------------------------------/n char is:%d/n Line is:%d/n word is:%d/n",nc,lc,wc);
}

运行结果如下:
BENET-LRQ:~/c # cat hello.c |./count
count is begin(LRQ)
-------------------------------
#include
int main()
{
printf("Hell, The World!/n");
}

-------------------------------
 char is:64
 Line is:5
 word is:9

李荣权

你可能感兴趣的:(程序开发)