Given a string, remove the repeated characters from the string and print the unique characters of the string.
For Example: If the given string is "abcdcbad"
then the output string is "abcd"
For Example: If the given string is "abcdcbad"
then the output string is "abcd"
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void) {
/* This method uses hashing technique */
char *p="abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba"; //Input string
char s[55];
int i=0;
int hash[26];
/* Initializing hash array to zero */
memset(hash,0,sizeof(hash));
while(*p)
{
/* If the hash index of the character is not visited, copy the character to output array */
if(hash[*p-'a']==0)
{
*(s+i)=*p;
i++;
}
/* mark the hash index of the character as visited*/
hash[*p-'a']=1;
/* Increment the string pointer to traverse the string */
p++;
}
/* Mark the end of the result string with Null character '\0' */
*(s+i)='\0';
printf("%s",s);
return 0;
}