Good job! Just for your interest, here's how I would've done it.
(Actually, I probably would've used pointers instead of indices.)
The my_isspace function is similar to the built-in isspace function
(in header ctype.h) except it doesn't include '\v', '\r', or '\f',
which you don't seem to want (but you should check that out).
int my_isspace( char c )
return( c == ' ' || c == '\t' || c == '\n' );
int cleanSpace( char *s )
int i, // general loop index
first, // index of first non-whitespace character
last, // index of last non-whitespace character
found_space; // boolean: true if at least one whitespace was found
// Find the first non-whitespace character.
for( first = 0; s[first]; ++first )
if( !my_isspace( s[first] ))
// Find the last non-whitespace character.
for( last = strlen(s) - 1; last > first; --last )
if( !my_isspace( s[last] ))
// Move characters in string 's' between 'first' & 'last' to the
// beginning of string 's', converting one or more whitespace
// characters to a single space.
for( i = 0, found_space = 0; first <= last; ++i, ++first )
// While whitespace is found, skip past it.
while( my_isspace( s[first] ))
found_space = 1;
// If whitespace was found, write one space to 's'
if( found_space )
s[i++] = ' ';
found_space = 0;
// Copy next character
s[i] = s[first];
s[i] = '\0'; // Terminate the string
// Return the length of the modified string 's'.