C Programming Code Examples C > Strings Code Examples program to remove all repeated characters in a string program to remove all repeated characters in a string Write a C program to remove all repeated characters in a string using loops. How to remove all duplicate characters from a string using for loop in C programming. Program to find and remove all duplicate characters in a string. Logic to remove all repeated character from string in C program. Logic to remove repeated characters from string Input string from user, store it in some variable say str. Run a loop from start to end character of the given string str. For each character ch in the string, remove all next occurrences of ch. #include <stdio.h> #define maxsize 100 // Maximum string size /* Function declarations */ void removeDuplicates(char * str); void removeAll(char * str, const char toRemove, int index); int main() { char str[maxsize]; /* Input string from user */ printf("Enter any string: "); gets(str); printf("String before removing duplicates: %s\n", str); removeDuplicates(str); printf("String after removing duplicates: %s\n", str); return 0; } /* Remove all duplicate characters from the given string */ void removeDuplicates(char * str) { int x = 0; while(str[x] != '\0') { /* Remove all duplicate of character string[x] */ removeAll(str, str[x], x + 1); x++; } } /* Remove all occurrences of a given character from string. */ void removeAll(char * str, const char toRemove, int index) { int x; while(str[index] != '\0') { /* If duplicate character is found */ if(str[index] == toRemove) { /* Shift all characters from current position to one place left */ x = index; while(str[x] != '\0') { str[x] = str[x + 1]; x++; } } index++; } }