Jump to content
  • Advertisement
Sign in to follow this  
Winterhell

simple log function

This topic is 4405 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
Advertisement
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.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!