Re: sprintf: the format problem
From: Robert Stankowic (pcdoktor_at_netway.at)
Date: 12/19/03
- Next message: JV: "Re: i++ question"
- Previous message: Kevin Goodsell: "Re: sprintf: the format problem"
- In reply to: Huey: "sprintf: the format problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 19 Dec 2003 06:45:07 +0100
"Huey" <huey_jiang@yahoo.com> schrieb im Newsbeitrag
news:ae92bb50.0312182112.37f533b6@posting.google.com...
> Hi All,
>
> I saved hashed values of hex into buf[32], then buf becomes unreadable
> by the means of calling puts(buf), printf("%s") and so on. Then, I
> need to convert the hex in buf[] into a char buffer cbuf[32], by
> calling sprintf(). I did:
>
> sprintf(cbuf, "%x", buf);
Try
(CHAR_BIT == 8 assumed)
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int i;
unsigned char buf[32] =
{0, 1, 2, 3, 4, 5, 55, 66, 77};
char cbuf[97];
for(i = 0; i < 32; i++)
{
sprintf(cbuf + 3 * i, "%02x ", buf[i]);
}
puts(cbuf);
return EXIT_SUCCESS;
}
>
> No error! Just no working. Well, I used sprintf() a lot in format "%s"
> "%d", and liked sprintf. It is my first time of using it in format
> "%x". I wonder does format affect sprintf? Anybody can help me to get
> this trick? Thanks!
from N869:
o,u,x,X The unsigned int argument is converted to unsigned octal (o),
unsigned
decimal (u), or unsigned hexadecimal notation (x or X) in the style dddd;
the
letters abcdef are used for x conversion and the letters ABCDEF for X
conversion. The precision specifies the minimum number of digits to appear;
if the value being converted can be represented in fewer digits, it is
expanded
with leading zeros. The default precision is 1. The result of converting a
zero value with a precision of zero is no characters.
- Next message: JV: "Re: i++ question"
- Previous message: Kevin Goodsell: "Re: sprintf: the format problem"
- In reply to: Huey: "sprintf: the format problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|