网站如何做跳转,官网制作价格,杭州百度推广代理商,上海建站网络科技有限公司1.清除字符串中右边的空格 从字符串尾部开始#xff0c;找到非空格处#xff0c;将下一个字符置为0即可。 //清除右边空格
#includestdio.h
int main()
{char buf[] hello world ;int len 0;//calculate the length of stringwhile(buf[len]);le… 1.清除字符串中右边的空格 从字符串尾部开始找到非空格处将下一个字符置为0即可。 //清除右边空格
#includestdio.h
int main()
{char buf[] hello world ;int len 0;//calculate the length of stringwhile(buf[len]);len--;int i;for(i len - 1; i 0; i--){if(buf[i] ! ){buf[i1] 0; // buf[i1] \0break;}}printf(buf %s\n,buf);return 0;
} 2.清除字符串左边的空格。 确定字符串左边有多少个空格将字符串整体左移空格数将字符串最后位置0 //清除左边空格
#includestdio.h
int main()
{char buf[256] hello world;int len 0;while(buf[len] );len--;int i len;while(buf[i]){buf[i - len] buf[i];i;}buf[i - len] 0;printf(buf %s\n,buf);return 0;} 转载于:https://www.cnblogs.com/wanghao-boke/p/11031033.html