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

46 / 59

Write a program to remove duplicates from a given string

Answer:

#include 
#include 
int main()
{
    char str[] = "qqq44inttttervvviieewwww......commm";
    removeDuplicate(str);
    printf("%s",str);
    return 0;
}
void removeDuplicate (char *str)
{
    char hash[256] = {0};
    int x=0, y = 0;
    char temp;
    while (*(str+y) != '\0')
    {
        temp = *(str+y);
        if (hash[temp] == 0)
        {
            hash[temp]=1;
            *(str+x) = *(str+y);
            x++;
        }
        y++;
    }
    *(str+x)='\0';
}

Asked In ::

Post Your Answer Here:

Language:

Post Your Reply Here:



Language:

Post Your Reply Here: