Your code in the loop
Code:
for(i; i < size; ++i)
{
if((userString[i] != ' ') && (userString[i-1] != ' '))
{
tempString[i] = userString[i];
}
if((userString[i] == ' ') && (userString[i-1] == ' '))
{
++i2;
tempString[i] = userString[i-i2];
}
}
has a condition for two consecutive non-spaces, and two consecutive spaces, but no code for a space followed by a non-space and a non-space followed by a space. That is why nothing is being added to tempString in those cases. In such cases, you need to add both the character and the space.
Actually, I don't have a lot of faith in the code. I would do it like this. Keep two separate index counters, iTmp, and iUser for the temp and user strings and keep a flag lastSpace set to true if the last character added to the temp string was a space. When lastSpace is true, further spaces are not to be added. As soon as a non-space is added, lastSpace becomes false. Whenever a character is added to the tempString, increment iTmp, and increment iUser for every character consumed from the userString. Actually, if you think about it, iTmp <= iUser at all times, so you actually don't need a tempString. You can do it all in userString memory, but I suggest you work with 2 strings to start. It may be less confusing to you.