#include<stdio.h>
int main()
{
char s[1001];
gets(s);
int count=0;
int i=0;
while(s[i]==' ') //跳过开头的空格
i++;
while(s[i]!='\0')
{
if(s[i]!=' ')
{
count++;
while(s[i]!=' ') //跳过一个单词的其他字符
{
if(s[i]=='\0') //这句很重要,漏掉后出现严重错误
break;//最后一个单词
else{
i++;
}
}
}
else
{
while(s[i]==' ')
i++;
}
}
printf("%d\n",count);
}
习题6-8 统计一行文本的单词个数 (15分)
猜你喜欢
转载自blog.csdn.net/qq_38054511/article/details/104203581
今日推荐
周排行