void Log(const char *format, ...) { va_list ap; char buf[5 * 1024]; va_start(ap, format); vsnprintf(buf, sizeof(buf), format, ap); fprintf(fLogHandle, "%s\n", buf); fflush(fLogHandle); va_end(ap); }
Programming Tips - How can I make my own custom printf()-like function that accepts
Date: 2014sep26
Language: C/C++
Keywords: snprintf, vsprintf, vprintf, vargs, variadic
Q. How can I make my own custom printf()-like function that accepts
a variable number of arguments?
A. Use the va_* family of functions like this: