Indeed, flag 0 only works for numerical conversions. You will have to do this manually:
int print_padleftzeroes(const char *s, size_t width) { size_t n = strlen(s); if(width < n) return -1; while(width > n) { putchar('0'); width--; } fputs(s, stdout); return 0; }
source share