Usenet.com

www.Usenet.com

Group Index

Comp Thread Archive from Usenet.com

<-- __Chronological__ --> <-- __Thread__ -->

Re: error in hh length modifier when used with sscanf



Yeah, I believe that. But I still think it's wrong. Moreover, as far as I
can find, my copy of "MS VS .net" doesn't even claim to support hh so it's
not much of a point of reference.

Testing x, hx, and hhx, stores 4 bytes, 2 bytes, and 4 bytes. Not clear what
hh is supposed to do (on input) if it's not meant for storing 1 byte.

Bill

"jacob navia" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> The output of msvc is exactly the same as lcc...
>
> "Bill Bennett" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > In this code snippet:
> >
> > unsigned char buffer[] = "$$$$$$$$";
> > for (int i=0; i<8; i++) printf("%6x ", buffer[i]); printf("\n");
> > sscanf("55", "%hhx", buffer+2);
> > for (int i=0; i<8; i++) printf("%6x ", buffer[i]); printf("\n");
> >
> > I expect
> >     24     24     24     24     24     24     24     24
> >     24     24     55     24     24     24     24     24
> > but I get
> >     24     24     24     24     24     24     24     24
> >     24     24     55       0       0       0     24     24
> >
> > In other words, I expected one byte to be stored but instead 4 are
stored,
> > trampling adjacent bytes.
> >
> > Using %hx instead of %hhx has the correct result, only 2 bytes are
stored.
> >
> > Seems like an error in how the hh is handled, right?
> >
> >
>
>





<-- __Chronological__ --> <-- __Thread__ -->


Usenet.com



Please check out one of the premium Usenet Newsgroup Service Providers below for access to Usenet.