Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 49: Write a C++ program to split string by space into words.

#include<iostream>
using namespace std;

int main()
{
	char str[100];
	cout<<"\nenter a string : ";
	gets(str);
	cout<<"\nwords in a given string :\n";

	for(int i=0;str[i]!='\0';i++)
	{
		if(str[i]==' ')
			cout<<"\n";
		else
			cout<<str[i];
	}
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.