You can store each digit in an array:
} else {
char arr[32];
int counter = 0;
while (d != 0) {
int radix;
radix = d % b;
d = d / b;
char basechars[] = "0123456789ABCDEF";
arr[counter++] = basechars[radix];
}
if (counter == 0)
arr[counter++] = '0';
arr[counter++] = '';
print_rev(arr);
printf("
");
}
and then print the string using a recursive function (it will reverse the output):
void print_rev(const char *s)
{
if (*s) {
print_rev(s + 1);
printf("%c", *s);
}
}
or directly:
} else {
char arr[32];
int counter = 0;
while (d != 0) {
int radix;
radix = d % b;
d = d / b;
char basechars[] = "0123456789ABCDEF";
arr[counter++] = basechars[radix];
}
if (counter == 0) {
printf("0");
else {
while (counter--)
printf("%c", arr[counter]);
}
printf("
");
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…