标签:
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));
标签:
原文地址:http://www.cnblogs.com/ryansunyu/p/4496751.html