Take FREE!! Online Mettl Mock Test to Crack TechM and Other Companies Written Exams.
Get Off-Campus Placement Jobs Info !!!
Practice Tech Mahindra Essay Topics

Program Discussion :: Strings

Home > Programs > Strings

47 / 59

Write an efficient program to remove characters from the first string which are present in the second string

Answer:

#include 
char *removeChar(char *str, char *mask);
int main()
{
char str[] = "q4interview.com";
char *mask = "iewc";
char *output = removeChar(str, mask);
printf("%s",output);
}

char *removeChar(char *str, char *mask)
{
    char arr[256] = {0}, temp;
    int i = 0,j=0, k=0;
    while (*(mask+i))
    {
        arr[mask[i]]++;
        i++;
    }
    while (*(str+k))
    {
        temp = *(str+k);
        if (arr[temp] == 0)
        {
            *(str+j) = *(str+k);
            j++;
        }
        k++;
    }
    *(str+j)='\0';
    return str;
}

Asked In ::

Post Your Answer Here:

Language:

Post Your Reply Here: