• Advertisement
Sign in to follow this  

Checking for repeated characters in a character array

This topic is 4322 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having some problems doing this... my plan was to take the last letter in my array and then check it against all of the preceding letters to see if their were any duplicates (example: In the name John Smith it would meet this condition when the cycle compared the third term to the last) and if so change that dupicate to a space ( this is mainly because I already have a function that will remove spaces and change all the letters to caps and so fourth...) But it's not working so well. My code is currently: i=0; j=2; length=strlen(encrypter); k=strlen(encrypter); for (k=length-1; k>=0; k=k-1) { for (i=0; i<length-j; i++) { if (encrypter[k]==encrypter) { encrypter[k]=' '; } j++; i=length-j; } i=0; } It only ever eliminates one letter in the array though...

Share this post


Link to post
Share on other sites
Advertisement
I don't see why you make it so complicated. What is the variable j for?
Try this way:

for (i = 0; encrypter != 0; ++i)
for (j = i + 1; encrypter[j] != 0; ++j)
if (encrypter == encrypter[j])
encrypter = ' ';

I haven't tested this, but it should work.

Share this post


Link to post
Share on other sites
You made me feel stupid now *tear*....

Oh well thank you very much, I just need to not do logic for a while...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement