单词计数
#include#define WORD_OUT 0 #define WORD_IN 1 int main() { int c; int ncharcount = 0; int nlinecount = 0; int nwordcount = 0; int wordlast = WORD_OUT; c = getchar(); while (c != EOF) { ncharcount++; if('n'==c) { nlinecount++; } if (('n' == c) ||( 't' == c) ||( ' ' == c)) { wordlast = WORD_OUT; } else { if (wordlast==WORD_OUT) //注意是双等号,如果是单等号,即判断是否为真为假。wordlast=0,为假不执行 { nwordcount++; wordlast = WORD_IN; } } c = getchar(); } printf("ncharcount=%d nwordcount=%d nlinecont=%d", ncharcount, nwordcount, nlinecount); }



