[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

/ 60

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: