delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/23/17:17:44

From: Jason Green <news AT jgreen4 DOT fsnet DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Weird output of printf()
Date: Sun, 23 Jan 2000 21:16:15 +0000
Organization: Customer of Planet Online
Lines: 36
Message-ID: <16rm8s0fdis7s8qbgprobresl8dd94usua@4ax.com>
References: <388B34AB DOT CA34EBD9 AT ou DOT edu> <4nhm8s4eqkb8mvicavhlv866qio80e0h8l AT 4ax DOT com> <388B549C DOT A2C038D AT ou DOT edu>
NNTP-Posting-Host: modem-21.carnival.dialup.pol.co.uk
Mime-Version: 1.0
X-Trace: news5.svr.pol.co.uk 948662539 9593 62.136.143.149 (23 Jan 2000 21:22:19 GMT)
NNTP-Posting-Date: 23 Jan 2000 21:22:19 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Newsreader: Forte Agent 1.7/32.534
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

David Cleaver <davidis AT ou DOT edu> wrote:

> Well, if you really want to know the print line I'm using is:

It is not a case of wanting to know.  Damian needed more information
because he wanted to help you.

> Anyway,  does the compiler actually think that 0xf is the same as 0x0f? 

Yes, 0xf *is* the same as 0x0f (and so are 0x0000000F and 15 and 017).

> Ok, If I have four char's {0x0f, 0x0f, 0x01, 0x07}
> and I want to convert it to an int I just combine them all into:
> {0x0f0f0107} right?
> Please tell me if this is correct.

Yes and No.  It is correct for what you want to do, but there are some
situations where the byte order is important.

> So, would the compiler be able to recognize if I chaged the array:
> from {0xf, 0xf, 0x1, 0x7} to {0xff17}?
> 
> I don't think so. So, I would like for printf (or fprintf) to print out
> the leading zero so I don't have to go back and add all of them.  Any
> help that you can give will be appreciated very much.

How about printing the whole 32-bit value with something like this:

fprintf(out, "0x%02x%02x%02x%02x", 
                array0[looper1][looper2],
                array0[looper1][looper2+1],
                array0[looper1][looper2+2],
                array0[looper1][looper2+3]);

C language questions like this (and some others you've asked) would be
better put in groups such as alt.comp.lang.learn.c-c++ and comp.lang.c

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019