I'm looking for suggestions on how to format a binary number so that after every 4th digit there's a space. I have a C program that converts a decimal number to binary but it just gives a long string with no spaces like "10000000" and I want it to be "1000 0000"
EDIT: here's the code
#include "binary.h"
char* binary(int num)
{
int i, d, count;
char *pointer;
count = 0;
pointer = (char*)malloc(32+1);
if(pointer == NULL)
exit(EXIT_FAILURE);
for (i = 31; i >= 0; i--)
{
d = num >> i;
if (d & 1)
*(pointer + count) = 1 + '0';
else
*(pointer + count) = 0 + '0';
count++;
}
*(pointer+count) = '\0';
return pointer;
}