I'd like to have a helper function log
that essentially does the following:
log(file, "array has %d elements\n", 10);
// writes "2014-02-03 16:33:00 - array has 10 elements" to &file
I have the time portion down, and I have the file writing portion down. However, the problem is the method signature itself for log
— what should I put? This says that the printf
declaration ends with the ...
keyword, but how can I use this in my function?
void log(FILE *f, const char * format, ...) // how would I pass ... to fprintf?
Let me EDIT this to include a bit more information.
I have a const char * now ()
that returns a string of the form "2014-02-03 16:33:00." I would like to pass another format string in like this. The two statements should be equivalent:
log(file, "array has %d elements\n", 10);
fprintf(file, "%s - array has %d elements\n", now(), 10);
I know that vfprintf
allows me to pass a va_list
, but how can I put the now()
as the first argument, before all the others?