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

来源:互联网 发布:appstore美区软件 编辑:程序博客网 时间:2024/04/30 05:46
#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;  }



老师,为何两次结果是一样的?哪里错了吗?

0 0