Re: int to ascii character?
- From: "Oliver Münchow" <omuenchow_AT_gesytecDOTde>
- Date: Tue, 24 May 2005 17:40:28 +0200
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
>
>
.
- References:
- int to ascii character?
- From: David++
- RE: int to ascii character?
- From: David++
- Re: int to ascii character?
- From: Oliver Münchow
- Re: int to ascii character?
- From: David++
- Re: int to ascii character?
- From: David++
- int to ascii character?
- Prev by Date: Re: Menus make things go faster! Why?
- Next by Date: Re: Serial Communication using Microsoft Pocket PC 2003 SDK?
- Previous by thread: Re: int to ascii character?
- Next by thread: Re: int to ascii character?
- Index(es):
Relevant Pages
|