People say use vprintf
instead of printf
. But I can't because I need to use a function of my own.
- I have 2 custom functions
- both use va_list
- one function uses the other function
So is it possible to chain the va_list
calls without having those v... functions ? And how ?
Code:
char* createString(const char* line, ...)
{
char* result = (char*)malloc(100);
va_list args;
va_start(args, line);
vsprintf(result, line, args);
va_end(args);
return result;
}
void show(const char* line, ...)
{
va_list args;
va_start(args, line);
char* a = createString(line, args);
va_end(args);
AfxMessageBox(a);
free(a);
}
// usage:
show("test %i, %i", 12, 123);
When I try this I get wrong strings displayed. Instead of 12 and 123 I get some pointers or stuff.
Sad solution:
char* vCreateString(const char* line, va_list args)
{
char* result = (char*)malloc(100);
vsprintf(result, line, args);
return result;
}