Skip the spaces at the beginning with a while(isspace(...)), and then memmove the string from the position you reached to the beginning (you can also do the memmove work manually with the classic "trick" of the two pointers, one for read and one for write).
You start from
[ ][ ][H][e][l][l][o][ ][W][o][r][l][d][ ][ ][\0]
^
[ ][ ][H][e][l][l][o][ ][W][o][r][l][d][ ][ ][\0]
^ skipping the two spaces you move your pointer here
... and with a memmove you have...
[H][e][l][l][o][ ][W][o][r][l][d][ ][ ][\0]
Then, move your pointer at the end of the string (you can help yourself with a strlen), and go backwards until you find a non-space character. Set the character after it to 0, and voilà, you just cut the spaces off the end of your string.
v start from the end of the string
[H][e][l][l][o][ ][W][o][r][l][d][ ][ ][\0]
... move backwards until you find a non-space character...
v
[H][e][l][l][o][ ][W][o][r][l][d][ ][ ][\0]
.... set the character after it to 0 (i.e. '\0')
[H][e][l][l][o][ ][W][o][r][l][d][\0]
... profit!