You can probably avoid the segfault by changing scanf("%d",dec);
to scanf("%d",&dec);
, and if you want printable results, change *(array+index)=(char)mask;
to *(array+index)=(char)mask+'0';
(or, better, array[index] = mask + '0';
printf(to_hex(dec));
is a bit iffy, too. Use printf("%s",to_hex(dec));
instead; it's safer.