Archived

This topic is now archived and is closed to further replies.

Writing logfiles

This topic is 5530 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

Ive just followed the GameDev article on logfiles: http://www.gamedev.net/reference/articles/article1352.asp that suggests a function like this:
  
BOOL ADXL_LogText(char *lpszText, ...)
{
  // only do this if logging is enabled

  if (bLogEnabled)
  {
    va_list argList;
    FILE *pFile;

    // initialize variable argument list

    va_start(argList, lpszText);

    // open the log file for append

    if ((pFile = fopen("log.txt", "a+")) == NULL)
    return(FALSE);

    // write the text and a newline

    vfprintf(pFile, lpszText, argList);
    putc(''\n'', pFile);

    // close the file

    fclose(pFile);
    va_end(argList);
  }

  // return success

  return(TRUE);
}
  
The article says it should accept a variable number of arguments of any type, so I assumed I could use it like this: ADXL_LogText("Enumerated adapters."); ADXL_LogText("Number of adapters found: ",intAdapters); ADXL_LogText("Connected to ",strIpAddress); Unfortunately the logfile output looks like this: Enumerated adapters. Found possible adapters: Connected to Only the first argument (lpszText) is being written to the logfile. Is there something I should be #including or am missing that the tutorial doesn''t mention.

Share this post


Link to post
Share on other sites
He doesn''t give an example of how to use that function, does he?

You use it just like printf. The variables get inserted into your first string, and you have to stick some special characters in there to show where they get inserted.


// integer
ADXL_LogText("Number of adapters found: %d",intAdapters);
// string
ADXL_LogText("Connected to %s",strIpAddress);
// two integers
ADXL_LogText("Printing page %d of %d",intCurrentPage, intTotalPages);

Share this post


Link to post
Share on other sites