Posted by Kwisatz Haderach on 2000-04-30
> Hi, am using C, and have to reduce a string down to
> just single occurances
> of individual letters, that is , no repeats of the
> same letter.
>
> eg) abfaghb goes to abfgh
>
> the order needs to be kept as I would like to put
> the result in a 5x5
> matrix. Any help on this part would also be
> appreciated
I know this has been answered many times and you've
got it working, but an easy way to reduce a string
would be something like this:
//assuming we're working with just lc/uc alphabet
char reduced[26] = "";
void reduce(char *str)
{
int n;
for(n = 0; n < strlen(str); n++)
if(!strchr(reduced, str[n]))
reduced[strlen(reduced)] = str[n];
}
Just thought you might like to know... BTW, you could
return a string instead of using a global variable, or
you could store the reduced string in a local variable
and copy it over the original string... you could do a
lot of things, but I think you get the general idea...
Cheers,
Sharvil Nanavati
__________________________________________________
Do You Yahoo!?
Talk to your friends online and get email alerts with Yahoo! Messenger.
http://im.yahoo.com/
Previous post | Next post | Timeline | Home