计算单词个数

#include<stdio.h>

int fun(char *p)
{
 int cnt = 0;
 char *q=p;
 while(*q != '\0')
 {
  if((*q == 32) && (*(q+1) != 0))
  {
   cnt++;
   
  }
  q++;
 }
  if(*p != 32)
   cnt+=1;
 printf("%d\n",cnt);
 return cnt;

}

int main()
{
 char a[]={" how do you do! "};
 fun(a);
 return 0;
}

猜你喜欢

转载自blog.csdn.net/yyq1w2e3/article/details/6649212