Browse - Programming Tips - How can I make my own custom printf()-like function that acceptsDate: 2014sep26 Language: C/C++ Keywords: snprintf, vsprintf, vprintf, vargs 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: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); } Add a commentSign in to add a comment![]()
|