In C++:
int main()
{
cout << setfill('#') << setw(10) << 5 << endl;
return 0;
}
Outputs:
#########5
Is there any setfill()
alternative for C? Or how to do this in C without manually creating the string?
int x= 5;
printf("%010d",x);
will output : 0000000005
Now if you really want '#' instead of '0' you'll have to replace them manually in the string.
Maybe :
char buf[11], *sp = buf;
snprintf(buf, 11, "%10d", x);
while( (sp = strchr(sp, ' ')) != '\0'){ *sp = '#'; }
puts(buf);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With