Linux 下去除字符串首尾空格的函数
看了很多个,这个挺简单的,可是发现居然达不到想要的功能;
当输入字符串为“ a dd ”,处理后的字符串为“a”,想修改成处理后为“a dd”
思路很乱,烦请指点一二
char *rtspace(char *str)
{
char *it;
int i,j;
while( *str == ' ' && *str)++str;
it=str;
while( *it == ' ' && *it)++it;
str=it;
strrev(str);
return str;
}
[解决办法]
- C/C++ code
char *rtspace(char *str) { char *it=NULL; //指针最好初始化下while( *str == ' ' && *str)++str; it=str; while(*str)str++; //指针定到末尾while(*(--str)==' '); //去除最后的空格*(++str)='\0';return it;}