第二周实验报告4

#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;
}

 

第二周实验报告4_第1张图片

 

你可能感兴趣的:(include)