去右空格

来源:互联网 发布:贴吧千里眼软件 编辑:程序博客网 时间:2024/06/05 08:10
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


char * rtrim(char *str)
{
char *s=str;
while( *s )
{
++s;
}
--s;
while( s >= str )
{
if((*s==' ') || (*s=='\t') || (*s=='\r') || (*s=='\n') )
{
*s=0;
--s;
}
else
break;


}
return str;
}


int main()
{
char a[10];
memcpy(a,"abc      ",9);
rtrim(a);
printf("%s##\n",a);

}

PS.rtrim函数是对地址做处理。

0 0
原创粉丝点击