: : : hi there...
: : :
: : : i have a problem here..how to remove duplicate chars from a string
: : : example:
: : : input AAA BBB CCC
: : : output A B C
: : :
: : : can anybody help me...
: : :
: :
: : the string::at(int index) function lets you get a hold of individual characters, so you need to have an array to hold all characters. Then make a loop and read each character in the string and compare them to what is in your other array.
: :
:
: then how to remove the duplicated chars, can you show me some code..
: thanks..
:
:
Here is a simplest way, but not the fastest one:
char* deldupchars (char* s) {
char* dups = strdup (s);
if (dups) {
char* psrc = dups;
char* pdest = s;
char ch;
pdest [0] = '\0';
while ((ch = *psrc++) != '\0') {
if (! strchr (pdest, ch)) {
*pdest++ = ch;
}
}
pdest [0] = '\0';
free (dups);
}
return s;
}