Use vprintf
, which is declared as:
int vprintf(const char *format, va_list ap);
In your log
function, invoke va_start
to obtain a va_list
value, then pass that value to vprintf
.
Since your log
function takes a FILE*
argument, you'll probably want to use vfprintf
rather than vprintf
(and perhaps update your question to ask about fprintf
rather than printf
).
Incidentally, you might want to reconsider using the name log
; that's the name of a standard function declared in <math.h>
.
Reflecting your updated question, you can print the timestamp inside log
by calling fprintf
directly:
va_list(args);
fprintf(f, "%s - ", now());
va_start(args, format);
vfprintf(f, format, args);