C语言实现trim函数
// 截去左面的空格int TrimLeft(char *s){ int i=0, j=0; //传入空值则退出 if(!strlen(s)) return; //找到首个不为空的字符 while( s[i] == ' '&& s[i] != '\0') i++; //从i位置的字符开始左移i个位置 while( s[i] != '\0') s[j++] = s[i++]; s[j] = '\0';}// 截去右边的空格int TrimRight(char *s){ int pos; pos = strlen(s) - 1; //若尾部字符为空,则将其设置为末尾字符 while( s[pos] == ' ' ) { s[pos--] = '\0'; if(pos<0) break; }}// 去除左右的空格int Trim(char *s){ TrimLeft(s); TrimRight(s);}