Tuesday 24 June 2014

C++ program to delete a character from a string


Here is a C++ program to delete a character from a string


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

Any questions regarding to program please write in comments.

No comments:

Post a Comment