Re: printf("%#04x\n", 0); print 0000 not 0x00
- From: Jack Klein <jackklein@xxxxxxxxxxx>
- Date: Thu, 30 Jun 2005 21:51:01 -0500
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
.
- Follow-Ups:
- Re: printf("%#04x\n", 0); print 0000 not 0x00
- From: Peter Nilsson
- Re: printf("%#04x\n", 0); print 0000 not 0x00
- References:
- printf("%#04x\n", 0); print 0000 not 0x00
- From: baumann@pan
- printf("%#04x\n", 0); print 0000 not 0x00
- Prev by Date: Re: printf("%#04x\n", 0); print 0000 not 0x00
- Next by Date: Re: printf("%#04x\n", 0); print 0000 not 0x00
- Previous by thread: Re: printf("%#04x\n", 0); print 0000 not 0x00
- Next by thread: Re: printf("%#04x\n", 0); print 0000 not 0x00
- Index(es):
Relevant Pages
|