单词计数

1. 统计行数、单词数与字符数

2. 单词认为是任何其中不包含空格、制表符或换行符的字符序列

#include <stdio.h>
#include <Conio.h>
#define IN 1
#define OUT 0
main()
{
    int nl,nw,nc,input,state;
    nl = nw = nc = 0;
    state = OUT;
    while((input=getchar())!=EOF){
        ++nc;
        if(input== '\n'){
            ++nl;
        }
        if(input ==' ' || input == '\t' || input == '\n'){
            state = OUT;
        }
        else if(state == OUT){
            state = IN;
            ++nw;
        }
    }
    printf("number of line is: %d, number of character is: %d, number of new word is: %d", nl, nc, nw);
    getch();
}

tips:

赋值由右向左,n1 = (nw = (nc = 0));

posted @ 2015-05-12 11:06  平静缓和用胸音说爱  阅读(193)  评论(0编辑  收藏  举报