c - 这个函数为什么不起作用?
本文介绍了c - 这个函数为什么不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
char* saowei(char *shu)
{
for(int len=strlen(shu);len>=0;len--)
if(*(shu+len-1)!='0')
{
*(shu+len)=='\0';
break;
}
return shu;
}
就是想把字符串数字尾部的0去掉 为什么没反应呢 输进去12300 返回还是12300
解决方案
别的不说,你的代码逻辑有点难懂。
char* saowei(char* shu){
while (shu[strlen(shu) - 1] == '0') shu[strlen(shu) - 1] = '\0';
return shu;
}
这篇关于c - 这个函数为什么不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文