Print all distinct characters of a string in order ( 3 Methods ) | C ++ program to print distinct characters of a string . ; Print duplicates present in the passed string ; Create an array of size 256 and count of every character in it ; Count array with frequency of characters ; Print characters having count more than 0 ; Driver program
# include <iostream> NEW_LINE using namespace std ; # define NO_OF_CHARS  256 NEW_LINE void printDistinct ( char * str ) { int count [ NO_OF_CHARS ] ; int i ; for ( i = 0 ; * ( str + i ) ; i ++ ) if ( * ( str + i ) != ' ▁ ' ) count [ * ( str + i ) ] ++ ; int n = i ; for ( i = 0 ; i < n ; i ++ ) if ( count [ * ( str + i ) ] == 1 ) cout << str [ i ] ; } int main ( ) { char str [ ] = " GeeksforGeeks " ; printDistinct ( str ) ; return 0 ; }