查找句子中单词数,串

#include<stdio.h>

int main()
{
char str[90];
int i,num=0,word=0;
char c;
gets(str);//赋值字符串
for(i=0;(c=str[i])!=’\0’;i++)//只要不是\0就可以继续循环
if(c==’ ‘)//如果是空字符就使word制零
word=0;
else if(word==0)//word=0且c不是空格,说明加入新单词
{
word=1;
num++;
}
printf(“there are %d word in this line \n”,num);
}

猜你喜欢

转载自blog.csdn.net/qq_41661800/article/details/81705003