can anyone tell me what is wrong with my code? its print out 100000 and then some weird symbols when i input 5 as my value. i know that at least the first number in the array should be zero because 2^9 definately does not have a mod greater than 0 when divinding into five
int *dec_binary(int i)
{
int n = 0;
int k = 1;
int *p = NULL;
while (i / 2) {
k++;
p = (int *)realloc(p, sizeof(int) * k);
p[n++] = i % 2;
i /= 2;
}
p[n++] = i;
p[n] = 9;
for (int k = 0; k < n / 2; k++) {
int temp = p[k];
p[k] = p[n - k -1];
p[n -k -1] = temp;
}
return p;
}