Re: printf("%#04x\n", 0); print 0000 not 0x00



On 30 Jun 2005 18:44:21 -0700, "baumann@pan" <asmboozer@xxxxxxxxxxx>
wrote in comp.lang.c:

> hi all,
>
> i hope
> printf("%#04x\n", 0);
> will output 0x00,
> but visual c++ studio 6 outputs 0000.
>
> how can i get 0x00?
>
> thanks

By coding:

printf("0x%04x\n", 0U);

There is no way to get printf() to do what you want with the format
string you are using and a value of 0, since it obviously does not
want to. Here is what the C standard says about the '#' flag:

"For x (or X) conversion, a nonzero result has 0x (or 0X) prefixed to
it."

That does not prevent an implementation from putting 0x in front of
the output for a value of 0, but it also most certainly does not
require it to do so.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
.



Relevant Pages