call printf using va_list

Alex F picture Alex F · May 12, 2011 · Viewed 58.7k times · Source
void TestPrint(char* format, ...)
{
    va_list argList;

    va_start(argList, format);
    printf(format, argList);
    va_end(argList);
}


int main()
{
    TestPrint("Test print %s %d\n", "string", 55);
    return 0;
}

I need to get:

Test print string 55

Actually, I get garbage output. What is wrong in this code?

Answer

Oliver Charlesworth picture Oliver Charlesworth · May 12, 2011

Use vprintf() instead.