Tuesday 24 June 2014

C++ program to replace a character with another character in string


Here is a C++ program to replace a character with another character in string


 SOURCE CODE OUTPUT
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char str[100],temp,rep;
    cout<<"Enter string : ";
    cin>>str;
    cout<<"Enter character : ";
    cin>>temp;
    cout<<"Enter character : ";
    cin>>rep;
    for(int i=0;str[i]!='\0';i++)
    {
        if(str[i]==temp)
            str[i]=rep;
    }
    cout<<"After replacing character : "<<str;
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment