Try doing it using two strings. The original and one to store the result. Read the original and write to the result only if there are no consecutive spaces.
EDIT: There's a smarter way, using istringstream ;)
Awesome, the istringstream works;) I'm just curious, because I used another implementation of the code in the original post, bit without the input being a pointer. It looks like this, and works fine: