String array

Hi, I have a string which the user entered and I am supposed to find the first pair of double letters in the string and move one of the letters to the beginning of the array and delete the other letter. I have been trying to figure out how to do it using something like pos=section.find(); but I don't think that's the correct way to go about it.
You might be better off just looping through the char array (the string) and checking to see if the previous letter is the same as the current one:
1
2
3
4
5
6
7
for (unsigned n = 1; n < s.length(); n++)  // notice how I start at '1' instead of '0'
  {
  if (s[ n - 1 ] == s[ n ])
    {
    // found a double letter
    }
  }

Once you've found the index of the pair, then you can modify the string using similar technique (using loops).

Hope this helps.
Helped alot, thanks! :)
There is an algorithm specifically designed to help with this type of problem.
http://cplusplus.com/reference/algorithm/adjacent_find/
Topic archived. No new replies allowed.