哦哦等几个有缘人
#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 = '-';
num = -num;
}
temp = num;
while (temp > 9)
{
dec *= 10;
temp /= 10;
}
while (dec != 0)
{
str = num / dec + '0';//这里的 “+‘0’ ”看不懂啊~~~~~~~
num = num % dec;
dec /= 10;
}
str = '\0';
return str;
}
int main(void)
{
char str;
printf("%s\n", myitoa(520, str));
printf("%s\n", myitoa(-1234, str));
return 0;
}str = num/dec+ '0' ;这里 +‘0’ 看不懂,谢谢解答!
这是字符类型,你要获得数字的ASCILL码,就得+'0'{:5_109:}
页:
[1]