Search code examples
cprintfvariadic-functions

call printf using va_list


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?


Solution

  • Use vprintf() instead.