我想要一个辅助功能log
它主要执行以下操作:
log(file, "array has %d elements\n", 10);
// writes "2014-02-03 16:33:00 - array has 10 elements" to &file
我有time https://stackoverflow.com/a/3673291/732016部分下来,我把文件的书写部分写下来。然而,问题在于方法签名本身log
— 我应该放什么?This https://stackoverflow.com/a/4178966/732016说printf
声明以...
关键字,但是我如何在我的函数中使用它?
void log(FILE *f, const char * format, ...) // how would I pass ... to fprintf?
Let me EDIT这包括更多信息。
我有一个const char * now ()
返回“2014-02-03 16:33:00”形式的字符串。我想像这样传递另一个格式字符串。这两个语句应该是等效的:
log(file, "array has %d elements\n", 10);
fprintf(file, "%s - array has %d elements\n", now(), 10);
我知道vfprintf
允许我通过va_list
,但我怎样才能把now()
作为第一个参数,before所有其他人?