Building the program below shows sprintf failing to zero pad the generated string when built on linux. It zero pads on all other unix platforms (and winnt). The following is the Linux man page snippet for zero padding: "0 specifying zero padding. For all conver- sions except n, the converted value is padded on the left with zeros rather than blanks. If a precision is given with a numeric conversion (d, i, o, u, i, x, and X), the 0 flag is ignored." #include <stdio.h> #include <stdlib.h> int main(argc, argv) int argc; char *argv[]; { char buff[20]; sprintf(buff, "%012s", "4D2"); /* ZERO pad */ printf("buff: '%s'\n", buff); return 0; } If I compile and run this code on linux 6.0 I get: buff: ' 4D2' If I compile it on any other platform i get: buff: '0000000004D2'
assigned to jakub
Zero padding is only available with numerical conversions (according to Ulrich Drepper), and both current man pages and info libc reflect this.