Sorry I couldn't get back to you earlier. Busy day!
However, your code makes my head hurt, so I'd rather suggest some pseudocode.
Try something like this:
1. Find first non-whitespace char (call it's index "first")
2. Find last non-whitespace char (call it's index "last")
Note: This requires that you search the string
backwards from the end.
3. Running index "i" from 0 to "last", including "last":
a. Increment "first" past any whitespace you find
b. If you found some whitespace, copy one space to
index "i" and increment "i"
c. str[i] = str[first]
d. Increment both "i" and "first"
4. Terminate string at index "i"
Also note that the function isspace(str[i])
returns true if the character is a space, tab,
vertical tab, form feed, carriage return, or newline. You may find that useful!