C language to achieve statistics string word number
- 2020-04-02 03:00:46
- OfStack
Number of string words. 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);
}
The above is the entire content of this article, I hope you can enjoy it.