Mail Archives: djgpp/2000/01/25/10:56:57
Jason Green <news AT jgreen4 DOT fsnet DOT co DOT uk> wrote:
> Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> wrote:
>> If you want the leading zero, use "%#0x" as your format specifier.
> This does not work (although I don't know that it should.)
> Apparent behaviour of printf is to ignore the 0 flag and the width
> field whenever the # flag is used.
Not really, I think. You're just a tid bit off in your format spec,
preventing it from doing what you want:
> If it should work then I would expect "%#02x" to be the required
Make that "%#04x", and it'll work. The '2' is too small, as it has to
count total output field width, including the "0x" added by that '#'
option in the format.
------ shell excerpt --------
E:\>type tt.c
#include <stdio.h>
int main(void) {
printf("%#04x\n", 0x0f);
return 0;
}
E:\>tt
0x0f
------- end ----------------
Alternatively, you could
printf("0x%02x\n", 0x0f);
Same result, easier to understand.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -