Possible Duplicate:
How do I trim leading/trailing whitespace in a standard way?
I need to remove all spaces from the beginning and at the end of the string for instance if my string is
" hello world. "
(without quotes), I need to print
"hello world."
I tried something like this:
size_t length = strlen (str);
for (newstr = str; *newstr; newstr++, length--) {
while (isspace (*newstr))
memmove (newstr, newstr + 1, length--);
but it removes all spaces.
How can I fix it?