|
6鱼币
- #include <stdio.h>
- char *myitoa(int num, char *str);
- char *myitoa(int num, char *str)
- {
- int dec = 1;
- int i = 0;
- int temp;
- if (num < 0)
- {
- str[i++] = '-';
- num = -num;
- }
- temp = num;
- while (temp > 9)
- {
- dec *= 10;
- temp /= 10;
- }
- while (dec != 0)
- {
- str[i++] = num / dec + '0';//这里的 “ +‘0’ ”看不懂啊~~~~~~~
- num = num % dec;
- dec /= 10;
- }
- str[i] = '\0';
- return str;
- }
- int main(void)
- {
- char str[10];
- printf("%s\n", myitoa(520, str));
- printf("%s\n", myitoa(-1234, str));
- return 0;
- }
复制代码 str[i++] = num/dec + '0' ;这里 +‘0’ 看不懂,谢谢解答!
这是字符类型,你要获得数字的ASCILL码,就得+'0' 
|
最佳答案
查看完整内容
这是字符类型,你要获得数字的ASCILL码,就得+'0'
|