This might help... it produces padded binary output and you may be able to adapt it to your program...
Code:
#include <stdio.h>
int main (void)
{ char binary[33] = {0};
unsigned int number;
int x = 0;
// get user input
printf("Enter a number from 0 to 4294967295 : ");
scanf("%u", &number);
// fill array with 0
while(x < 32)
binary[x++] = '0';
// crunch out binary number
do
binary[--x] = (number & 1) + '0';
while ( (number /= 2) > 0 );
// show it off
printf("32bit binary : %s\n\n", binary);
return 0; }