• ### Announcements

#### Archived

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

# Writing logfiles

## Recommended Posts

RedGenie    122
Ive just followed the GameDev article on logfiles: http://www.gamedev.net/reference/articles/article1352.asp that suggests a function like this:

{
// 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 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.

// integerADXL_LogText("Number of adapters found: %d",intAdapters);// stringADXL_LogText("Connected to %s",strIpAddress);// two integersADXL_LogText("Printing page %d of %d",intCurrentPage, intTotalPages);

##### Share on other sites
RedGenie    122
Thats the beauty, thanks v much!