Joe,
Thanks for your help. I ended up using vsnprintf which worked out great.
( I wanted to store the converted string and then write out the log file,
not just print it out like vprintf did).
Dan
"Joe Hotchkiss" <nospam@baesystems.com> wrote in message
news:42105f21$1_1@baen1673807.greenlnk.net...[color=blue]
> "winbatch" <hoffmandan@gmail.com> wrote in message
> news:1108341643.590006.293000@o13g2000cwo.googlegr oups.com...[color=green]
>> Hi,
>> I'm trying to write a function that accepts a string of some kind
>> (either char * or std::string) that can be passed something in printf
>> semantics.
>>
>> For example:
>>
>> void test( string passedIn )
>> {
>> ...etc..
>> }
>>
>> test( "Whatever: %s = %d", val, 3 );
>>
>> How would I write the test function to accept such a string so that it
>> can handle whatever is passed as a single string? (ie so that it will
>> get "Whatever: val = 3"[/color]
>
> #include <stdarg.h>
> #include <stdio.h>
>
> int test (const char* fmt, ...)
> {
> va_list args;
> int count;
>
> va_start (args, fmt);
> count = vprintf (fmt, args);
> va_end (args);
>
> return count;
> }
>
> int main ()
> {
> test ("Whatever: %s = %d\n", "val", 3);
>
> return 0;
> }
>
> vsprintf and vfprintf work similarly.
>
> --
> Regards,
>
> Joe Hotchkiss,
>
http://joe.hotchkiss.com
>
http://harrowsubaqua.org.uk
>
> XXXXXXXXXXXXXXXXXXXXXXXXX
> X joe.hotchkiss X
> X at baesystems.com X
> XXXXXXXXXXXXXXXXXXXXXXXXX
>
>
>[/color]