完成一个trim_string函数,将一个字符串两端的空格、回车、tab符号去掉。
void kill_space( char *str)
{
int i, j;
assert( str != NULL); //<assert.h>
/*find the first non-space char's position */
for (i = 0; (str[i] == ' ' || str[i] == '\t') && str[i] != '\0';i++)
;
/*find the last non-space char's position */
for (j = strlen(str) - 1;(str[j] == ' ' || str[j] == '\t') && j; j--)
;
memmove(str, str + i, j - i);// < String.h >
str[j + 1] = '\0';
}