simple log function

Started by
2 comments, last by Winterhell 17 years, 9 months ago
Hi,i dont know if it should be here or it was answered before,google didnt really help. I am trying to make a log(char *ctrlstr,...); It should take the same parameters as ANSI C printf() or something similar I see that way easier to debug,because i can know exactly where the process halted,or it'll help on error messages like "not enough memory","texture not found"; The problem is re-passing the arguments. void log(char *ctrlstr,...) {FILE *f; f=fopen("error.log","a"); if(f==NULL) return; fprintf(f,ctrlstrl, ??? ); fclose(f); } how to pass the arguments to fprintf ,something to replace the "???" place or analogous version. I couldnt find it in books,and yes,i need to use printf, i dont want the c++ implementations with streams,<< or something. Thanks in advance
Advertisement
Consider using vfprintf().
From my code:
static void Format(const char* szFormat, ...){   char szBuff[1024];   va_list arg;   va_start(arg, szFormat);   _vsnprintf(szBuff, sizeof(szBuff), szFormat, arg);   va_end(arg);   Log(szBuff);}
Where Log() just logs a normal const char* (You'd replace that with your call to fwrite() or whatever.
Thanks ;)

This topic is closed to new replies.

Advertisement