题目:
统计输出的文字有多少个单词
输入要求:
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;
}