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.
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
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.