|

楼主 |
发表于 2017-2-8 21:27:31
|
显示全部楼层
- #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';
- 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;
- }
复制代码
为什么小甲鱼老师写的答案返回了一个地址,却能打印出来 |
|