I needed to do this today, and it took me a while to google it, so here is complete sample showing how it's done:


// How to pass a variadic argument list to another function
// Justin

#include "iostream"
#include "stdarg.h"

using namespace std;

void debugMessageHelper(char *buffer, const char* format, va_list arglist)
{
vsprintf(buffer, format, arglist);
}

void debugMessage(char *buffer, const char* format, ...)
{
va_list arg;
va_start(arg, format);

debugMessageHelper(buffer, format, arg);

va_end(arg);
}

int main(int argc, char *argv[])
{
char testBuffer[128];

debugMessage(testBuffer, "hello %s %u %-04.2f", "world", 21 33.122f);

cout << "\'" << testBuffer << "\'" << endl;

}