不使用库函数将整数转化为字符串

来源:互联网 发布:windows firewall 编辑:程序博客网 时间:2024/04/28 07:45
不使用库函数将整数转化为字符串
实现代码如下:

void int2str(int n,char *str){char temp[10]="";int tem = n < 0 ? -n:n;//int i = 0;int j = 0;while(tem){   temp[i++] = (tem % 10) + '0';   tem = tem/10;}if(n < 0) {j = 1;str[0]='-';} while(i >=1) {str[j++] = temp[i -1];i--; }str[j]='\0';}




0 0
原创粉丝点击