[C]simple code of count input lines,words,chars

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
上一篇:解读SQL Server 2014可更新列存储索引——存储机制


下一篇:SQL Server临界点游戏——为什么非聚集索引被忽略!