C语言 - 统计输出的文字有多少个单词

来源:互联网 发布:nature数据库特点 编辑:程序博客网 时间:2024/04/27 23:19
题目:    统计输出的文字有多少个单词输入要求:hello human ni hao输出要求:There are 4 words in the line
// 指针,可能会有点繁琐#include <stdio.h>int main(){char a[999];char * e;int count = 0;gets(a);e = a;while(*e != '\0'){if( *e == ' ' || *e == '\t'){e++;continue;}if( (*e >= 'a' && *e <= 'z') || (*e >= 'A' && *e <= 'Z') ){count++;while(*e != '\0'){if( (*e >= 'a' && *e <= 'z') || (*e >= 'A' && *e <= 'Z') )e++;if( *e == ' ' || *e == '\t')break;}}}printf("您输入的有 %d 个单词\n", count);return 0;}


原创粉丝点击