您的位置:首页 > 其它

实验4(统计文本单词个数)

2014-11-16 09:16 288 查看
#include <stdio.h>
int count_word(char *str);
void main()
{
char str1[100];
int sum=0;
puts("请输入一个字符串:");
gets(str1);
sum=count_word(str1);
printf("这里有 %d 个单词\n",sum);
}
int count_word(char *str)
{
int count,flag,state;
char *p;
count=0;
state=0;
p=str;
while(*p!='\0')
{
if(*p==' ')
flag=0;
else if(state==0)
{
state=1;
count++;
}
p++;
}
return count;
}






老师,为何两次结果是一样的?哪里错了吗?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: