Date: Mon, 24 Jan 2000 09:29:15 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: David Cleaver cc: djgpp AT delorie DOT com Subject: Re: Weird output of printf() In-Reply-To: <388B549C.A2C038D@ou.edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com Errors-To: dj-admin AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Sun, 23 Jan 2000, David Cleaver wrote: > fprintf(out, "%#x", array0[looper1][looper2]); > where array0 contains unsigned char's > > Anyway, does the compiler actually think that 0xf is the same as 0x0f? > I personally think it should print out the leading zero If you want the leading zero, use "%#0x" as your format specifier. `fprintf' cannot know what do you want it to do except by looking at the format specifier that you provide. > So, would the compiler be able to recognize if I chaged the array: > from {0xf, 0xf, 0x1, 0x7} to {0xff17}? You are mixing two different things: how a value of a 8-bit byte is printed, and how it is packed into a 32-bit int. A value of 0xf (15 in decimal) can still occupy 8 bits, even if 4 bits are enough to express the value of 15.