您的位置:首页 > 其它

下学期第二周实验报告3(1)

2012-03-04 11:02 190 查看
实验目的:输入一行字符,统计其中有多少个单词。

项目代码:

#include <iostream>

#include "string.h"

using namespace std;

int main()
{
char str[200];
cin.get(str, 100, '\n');

for(int i = 0, j = 0; str[i] != '\0'; i++)
{
j++;
}
for(int x = 0, y = 0; x <= j; x++)
{
if(str[x] == ' ' &&str[x + 1] != ' ')
{
y++;
}
}
cout << "There are " << y + 1 << " words in the line." << endl;

return 0;
}


实验截图:



 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: