I'm trying to pass a decimal number to a function and convert it to binary and return it and print it out in main. But it prints out 1011 and then seg faults...not sure where it's tripping up
Code:int main(){ char* binNum = decToBin(25); int i = 0; while(binNum != NULL){ printf("%c", *(binNum+i)); i++; } } char* decToBin(int dec){ char* output = malloc(20*sizeof(char)); int i = 0; while(dec > 0){ if(dec % 2){ output[i] += '1'; } else{ output[i] += '0'; } dec /= 2; i++; } return output; }