0123456789 0123456789 - 2 months ago 17
C Question

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 neet to get:

Test print string 55


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

Answer

Use vprintf() instead.