[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Program Discussion :: Strings

Home > Programs > Strings

342 / 60

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: