My assignment is to print the binary value of a decimal number, and I want to control the size of the array as I understood I should do so my program would work in all the compilers.
I don't understand briefly the operator sizeof, but I would appriciate if you can explain where should I, and why, put the sizeof in my program:
void translate_dec_bin(char s[]){
unsigned int decNum;
char st[MAX_LEN] = { 0 };
int j = 0;
sizeof(decNum, 4);
decNum = atoi(s);
while (decNum > 0){
st[j] = decNum % 2;
decNum = decNum / 2;
j++;
}
while (j >=0){
printf("%d", st[j]);
j--;
}
printf("\n");
}
My thought is that when I print the number, i.e in the code:
printf("%d", st[j]);
I should put the operator. Is it right?