今天在一國外網站上, 看到下面的代碼, 覺得挺精簡.
代碼如下:
char *tr ( char *s )
{
int i = 0;
int j = strlen ( s ) - 1;
int k = 0;
while ( isspace ( s[i] ) && s[i] != '\0' )
i++;
while ( isspace ( s[j] ) && j >= 0 )
j--;
while ( i <= j )
s[k++] = s[i++];
s[k] = '\0';
return s;
}