so i have to make a function that displays the binary representation of a 32 bit integer
this is what i have
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#include<stdio.h>
void inttobin(int c)
{
char * s ;
char * p ;
size_t n = 8*sizeof(unsigned int);
p = malloc(n*sizeof(char));
while (n-- > 0){
s = ((c >> n) & 1) ? "1" : "0";
strcat(p,s) ;
}
printf("%s",p) ;
}
int main()
{
inttobin(0x1234567) ;
}
it prints out the right answer but with some garbage values at the first 3 characters of the string and I dont know how to fix it can you guys help me?