Re: int to ascii character?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi David,

ok, maybe i misunderstood something. Let's start again.
You have myInt with some value (e.g. 65). This value need to be printed as
ascii character into a string append with some other text or values??
If so, you should take a look at sprintf() and all its format parameters.
Here is some example code:
DWORD value = 65;
char message[0x100];
sprintf(message, "Some message. The value as decimal %d or simple hex %x or
readable hex 0x%08x or even as character %c\r\n", value, value, value,
value);

It's just a simple demo, but sprintf is a mighty function, cause through the
format string you're very flexible. You can also use a sprintf() function to
built the format string for another sprintf function like this one:
DWORD value = 65;
char message[0x100];
char format[0x100];
TCHAR output[0x100];
DWORD i;

for(i = 1; i <=8; i++)
{
sprintf(format, "Print a hex value with minimum lenght of %d. 0x%%0%dx and
some other char %%c\r\n", i, i);
sprintf(message, format, value, value);
swprintf(output, L"%S", message);
RETAILMSG(1, (output));
}

How you can see, it's also very usable to convert a single byte char to
unicode and vice versa (by using the %S placeholder). So if that don't help
or i didn't hit the right spot again, just post a message.

Best regards,
Oliver Münchow

"David++" <David@xxxxxxxxxxxxxxxxxxxxxxxxx> schrieb im Newsbeitrag
news:E9050A64-2BDE-4EBF-9D7A-662BBDDA15D0@xxxxxxxxxxxxxxxx
> Still not managing to make any progress with this.
>
> Example
>
> int myInt = 65;
> fprintf(myFile, "%c", myInt);
>
> This will print the charcater A in my file. However, I need to store this
> character i.e. A in my program and then append further characters to it
> (letters and numbers) i.e AB123456
>
> Example 2
>
> char buffer[50];
> _itoa(myInt, buffer, 10);
> fprintf(myFile, buffer);
>
> This will print "65" in my file. I need to store the value "A" in buffer,
> not "65".
>
> I know I can convert 65 to A using fprintf(myFile, "%c", myInt); However,
> I
> just cant get access to "A" to store it. There must be a quickish way to
> get
> access to this value and to store it for later use?
>
> Thanks again for any assistance,
>
>
> David
>
>


.



Relevant Pages

  • Re: diff o/p
    ...   int x; char ch; ... one is hard coded in your format string and the other is the value of ...  The first character goes into wherever ... After scanning the blank, ch contains 0x20. ...
    (comp.lang.c)
  • queries about sprintf
    ... I was wondering about the implications of giving as an argument to sprintf a ... different data type from the one specified in the format argument. ... char a in decimal is: ... every ASCII character is essentially an one-byte integer ...
    (comp.lang.c)
  • queries about sprintf
    ... I was wondering about the implications of giving as an argument to sprintf a ... different data type from the one specified in the format argument. ... char a in decimal is: ... every ASCII character is essentially an one-byte integer ...
    (comp.std.c)
  • Re: The "at" character @
    ... is the char 174. ... Character interpretations relate to a "character set" ... I try also to put in sprintf ... UTF-8 uses multiple bytes to represent everything above "ascii," ...
    (comp.sys.hp48)
  • The "at" character @
    ... I want to have the character @ in my hp. ... is the char 174. ... I try also to put in sprintf ... with latin-1 is it better? ...
    (comp.sys.hp48)