C语言实现统计字符串单词数
投稿:hebedich
这篇文章主要介绍了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);
}
以上所述就是本文的全部内容,希望大家能够喜欢。
