check repetitions in an array

I am working with some arrays of type char, and before i can use them, I need to check for any repeted characters in the array and delete them. Like for example, if I had two 'a' in the array, I would delete the second one and use only the first one in the function call. First I tried to use count variables to keep tally of all repeting characters, but that seems vague, now that I tried to write some actual code for it. Anybody has any ideas? All contributions are appreciated.
So what you are meaning is something like this?

1
2
3
4
5
6
void function_do(char* characters) {
   if(duplicate characters) {
       delete them
   }
   do something with the array (sort whatever)
}


Or is this just a function to clear the array of duplicate characters?
Convert the array into a std::set which prevents you from adding duplicates.

Just use std::unique
It is just a function to clear the array of any duplicate characters. I have the array declared as type char
char my_array[20]; and the function I want to write should be able to find and delete all duplications in the array. Thanks
Hi, I'm still waiting for any help on my issue. Thanks.
We gave you two solutions. If you must delete from an array (ie, school assignment) then post your non-working code and we'll help you fix it.
It's useless. Some people simply are "advisory-resistant", as a prof of mine puts it...
@jrok

It would be easier for an expert to understand your question and advise a suitable solution or work-around if you put the question right.

When you say "delete", meaning that the repeated character is deleted and replaced with the following character in the stream/array, to eliminate duplicates in a given string?
If I understand it right as noted above, then you would have to manipulate the string by replacing the duplicates with the following unique characters in the stream.
Again, this would be easier if your string (ie, character array) is sorted, otherwise it would be a nested loop to check the duplicates for each character and replace them with other uniques in the string.

If it sounds too big job for you, then you better go with the solutions or workarounds suggested by others.

Check it out. Good luck :)


Last edited on
thanks satm2008. I'll try ur idea too.
hey satm2008, I got the code working, I just used a combination of my and your logic. Thanks again.
Glad I could help you some.
Good luck :)
Topic archived. No new replies allowed.