您的位置:首页 > 编程语言 > C语言/C++

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

2013-12-09 21:45 507 查看
题目:
统计输出的文字有多少个单词
输入要求:
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C语言 王吉平
相关文章推荐