/*统计输入单词数等信息*/ #include #include //为isspace(ch)函数提供原型 int main(intargc, char *argv[]) { long count_char = 0;//字符数 intcount_chars = 0;//单词数 intcount_line = 0;//行数 intcount_half_line = 0;//半行数 char ch;//当前输入字符 char prech=' ';//前一个输入字符 const char STOP = '|';//结束字符 printf("Please enter an article(%c to terminate): \n",STOP); while((ch = getchar()) != STOP) { count_char++; if(!isspace(ch) &&isspace(prech))//当前字符非空&&前一个字符是 count_chars++; if(ch == '\n') count_line++; prech = ch; } if(prech != '\n') count_half_line++; printf("Char Count=%ld, Chars Count=%d, ", count_char, count_chars); printf("Line Count=%d, Half Line Count=%d.\n", count_line, count_half_line); return 0; } 本文来源:https://www.wddqw.com/doc/242faf21960590c69ec3769b.html