手机飞车游戏排行榜:利用C++如何编程:编写程序,统计一串字符中包含的单词数(假定单词以一个或多个空格分隔)。
来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 21:14:41
源码,谢谢
可以这样的解决你的这个问题。编译并且通过
#include <iostream.h>
#include <stdio.h>
void main()
{
char string[100];
int num=0,word=0;
char c;
gets(string);
for(int i=0;(c=string[i])!='\0';i++)
if (c==' ') word=0;
else if(word==0)
{
word=1;
num++;
}
cout<<"there are " <<num <<" words in the string\n ";
}