【#文档大全网# 导语】以下是®文档大全网的小编为您整理的《C语言 程序设计 统计单词个数 源代码》,欢迎阅读!
/*统计输入单词数等信息*/ #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.wddqxz.cn/242faf21960590c69ec3769b.html