+ 1

Base conversion in c ?

/* Program to convert from one base to another */ #include <stdio.h> int main(void) { char conversion_values[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; int num, base, converted_base[64], index = 0, index_store ; // Get base and number printf("Enter a number :"); scanf("%d", &num); printf("Enter a base:"); scanf("%d", &base); // Begins do{ converted_base[index] = num % base; index++; num = num / base; }while(num != 0); for (--index; index >= 0; index--){ index_store = converted_base[index]; printf("%d\n", conversion_values[index_store]); } } It returning unpredictable errors Why can anyone help me ?

28th Dec 2020, 1:35 PM
T.K.SANTHOSH
T.K.SANTHOSH - avatar
1 Réponse
+ 2
You are printing char with "%d", and since it's a number, you don't need a newline. You can also consider using putchar()
28th Dec 2020, 1:53 PM
你知道規則,我也是
你知道規則,我也是 - avatar