Friday, November 23, 2012

WRITE A C PROGRAM TO DELETE ALL THE OCCURENCES OF A CHARACTER IN A STRING.


/*   WRITE A C PROGRAM TO DELETE ALL THE OCCURENCES OF A 
     CHARACTER IN A STRING.
*/
#include<stdio.h>
#include<conio.h>

#define MAX 50

void main()
{
            char str[MAX],str2[MAX],ch;
            int i,j;
            clrscr();
            printf("Enter a string : ");
            gets(str);
            printf("Enter a chracter to delete it's occurences : ");
            scanf("%c",&ch);
            for(i=0,j=0;str[i]!='\0';)
            {
                        if(str[i]!=ch)
                                    str2[j++]=str[i];
                        i++;
            }
            str2[j]='\0';

            printf("The string after deleting \'%c\' is \n\t\t \"%s\" ",ch,str2);
            getch();
}

/*
            =====OUT PUT=====

            Enter a string : BHARATH
            Enter a chracter to delete it's occurences : H
            The string after deleting 'H' is
                             "BARAT"
*/

0 comments:

Post a Comment