Advertisement Jump to content
Sign in to follow this  

simple log function

This topic is 4561 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
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);

Where Log() just logs a normal const char* (You'd replace that with your call to fwrite() or whatever.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!