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

Program 50: Write a C++ program to replace a space with special character.

#include<iostream>
using namespace std;

int main()
{
	char str[100],str1[100],ch;
	cout<<"\nenter a string : ";
	gets(str);
	cout<<"\nenter a special character : ";
	cin>>ch;
	cout<<"\nnew string :\n";

	for(int i=0;str[i]!='\0';i++)
	{
		if(str[i]==' ')
			str1[i]=ch;
		else
			str1[i]=str[i];
	}
	puts(str1);
	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.