Wednesday 2 March 2016

Take a String input From User and Replace The Alphabets Given by User


SAMPLE OUTPUT :

CODE:
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    char str[50],f,r;
    cout<<"Enter the Sentence of Maximum 50 Words : "<<endl;
    gets(str);
    cout<<"Enter the word Which you Want To Replace : "<<endl;
    cin>>f;
    cout<<"\nEnter The Word You Want to Replace with : "<<endl;
    cin>>r;
    for(int i=0 ; str[i]!='\0' ; i++)
    {
        if(str[i]==f)
        {
            str[i]=r;
        }
    }
    cout<<str;
    return 0;
}


No comments:

Post a Comment