Trimming trailing spaces is easy. Just find the first space at the end and replace it with '\0'. But be careful that you clear the right character without going out of bounds for something like an empty string or a string with nothing but spaces.
Trimming leading spaces is harder. It's easiest if you can get away with just using a pointer into the array, then you can just do the inverse of the trailing technique and assign the first non-space character's address to a pointer.
If you don't have that option, you need to actually shift the string:
Code:
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int main ( void )
{
char a[] = " \t\v \nThis is a test\n \t \v ";
size_t walker = strlen ( a );
printf ( "Before: |%s|\n\n", a );
/* Trim trailing spaces */
while ( walker > 0 && isspace ( a[walker - 1] ) )
--walker;
a[walker] = '\0';
printf ( "Trailing: |%s|\n\n", a );
/* Trim leading spaces */
walker = strspn ( a, " \t\n\v" );
memmove ( a, a + walker, strlen ( a + walker ) + 1 );
printf ( "Leading: |%s|\n", a );
return 0;
}