C语言实现统计字符串单词数

字符串单词数.c

#include<stdio.h>
#define BUFFERSIZE 1024
 
int main()
{
 char string[BUFFERSIZE];
 int i,count=0,word=0;
 char c;
 gets(string) ;
 for(i=0;(c=string[i])!='\0';i++)
 {
  if(c==' ')
   word=0;
  else if(word==0)
  {
   word=1;
   count++;
  }
 }
 printf("%d \n",count);
}

以上所述就是本文的全部内容,希望大家能够喜欢。