Re: Help with va_list, va_start
- From: "Scherbina Vladimir" <vladimir.scherbina@xxxxxxxxx>
- Date: Fri, 23 Dec 2005 22:56:23 +0200
// The function
void FormatTest(const TCHAR* format, ...)
{
va_list args;
va_start(args, format);
TCHAR buf[1024] = {0};
wvsprintf(buf, format, args);
va_end(args);
}
void main (void)
{
// The test code
int val = 13;
FormatTest(("This is a test: %d"), val);
}
--
Vladimir
"buzz" <buzz@xxxxxxxx> wrote in message
news:%23ZYy$4$BGHA.2036@xxxxxxxxxxxxxxxxxxxxxxx
>I have a simple requirement....to develop a function that takes a parameter
>list like sprintf, and then pass it internally to sprintf. Everything
>compiles, but I don't get the answer is expect.
>
> // The function
> void FormatTest(const TCHAR* format, ...)
> {
> va_list args;
> va_start(args, format);
>
> TCHAR buf[1024];
> _stprintf(buf, format, args);
>
> va_end(args);
> }
>
> // The test code
> int val = 0x11223344;
> FormatTest(_T("This is a test: %X"), val);
>
> When I run the code, the buffer is filled with "This is a test: 2C20F9B8".
>
> When I examine the memory location at 0x2C20F9B8, I see my value
> 0x11223344.
>
> I tried using _sprintf(buf, format, (va_list)*args), but then I get "This
> is a test: 44".
>
> Can anyone tell me why this is not working, or show me how to make the
> code correct.
>
> Thanks!
>
> PS I see similar code in MFC8.
> PPS This code is running on a Pocket PC
.
- Follow-Ups:
- Re: Help with va_list, va_start
- From: buzz
- Re: Help with va_list, va_start
- References:
- Help with va_list, va_start
- From: buzz
- Help with va_list, va_start
- Prev by Date: Help with va_list, va_start
- Next by Date: Re: Help with va_list, va_start
- Previous by thread: Help with va_list, va_start
- Next by thread: Re: Help with va_list, va_start
- Index(es):
Relevant Pages
|