From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: Weird output of printf() Date: 25 Jan 2000 09:28:12 GMT Organization: Aachen University of Technology (RWTH) Lines: 40 Message-ID: <86jqbc$49u$1@nets3.rz.RWTH-Aachen.DE> References: <388B549C DOT A2C038D AT ou DOT edu> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 948792492 4414 137.226.32.75 (25 Jan 2000 09:28:12 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 25 Jan 2000 09:28:12 GMT User-Agent: tin/1.4-19991113 ("No Labels") (UNIX) (Linux/2.0.0 (i586)) Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Jason Green wrote: > Eli Zaretskii 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 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.