输入一个由若干单词组成的文本串,每个单词之间用一些空格分隔,统计此文本串中单词的个数
来源:百度知道 编辑:UC知道 时间:2024/06/27 16:59:26
请给个用C++的源程序!急用,谢谢啦!
#include<stdio.h>
void main()
{
char str[81];
int i,num=0,word=0;
char c;
cout>>"please input the string:\n";
gets(str);
for(i=0;(c=str[i])!='\0';i++)
{
if(c==' ')
word=0;
else if(word==0)
{
word=1;
num++;
}
}
cout>>"There are %d words in the line.\n">>num;
}