Red Hat Bugzilla – Bug 14190
sprintf does not zero pad with %s
Last modified: 2008-05-01 11:37:56 EDT
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."
sprintf(buff, "%012s", "4D2"); /* ZERO pad */
printf("buff: '%s'\n", buff);
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:
assigned to jakub
Zero padding is only available with numerical conversions (according to Ulrich
and both current man pages and info libc reflect this.