單詞計數

1. 統計行數、單詞數與字符數spa

2. 單詞認爲是任何其中不包含空格、製表符或換行符的字符序列code

#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:blog

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

相關文章
相關標籤/搜索