9
Here is how linux kernel does the trimming, called strstrip():
char *strstrip(char *s)
{
size_t size;
char *end;
size = strlen(s);
if (!size)
return s;
end = s + size - 1;
while (end >= s && isspace(*end))
end--;
*(end + 1) = '\0';
while (*s && isspace(*s))
s++;
return s;
}
Its basically a better formatted and error-checked version what the previous poster said.
If you're on Linux/Windows and have the library glib linked into your program, you can use the the routine g_strstrip().