Replacing a char in a given statement/paragraph

Category:

//Replacing a char in a given statement/paragraph
#include < iomanip >
#include < iostream >
using namespace std;
void main()
{
char sent[30],sv,repv,temp;
cout << "Enter your Statement here:: less than 30 words" << endl;
cin.getline(sent,30);
int i=0,len=strlen(sent);
cout << "Character should be replaced:: ";
cin>>sv;
cout << "Character " << sv << " Relaced with ";
cin>>repv;
temp=sent[len-1];
sent[len-1]=sv;
while(i < len)
{
while(sent[i]!=sv)
{
i++;
}
sent[i]=repv;
i++;
}
if(temp!=sv)
{
sent[len-1]=sv;
}
cout << sent;
system("pause");
}

Comments (0)

Post a Comment