
Patrick B. answered 06/27/19
Math and computer tutor/teacher
/* should be placed in debug.h */
#include <stdio.h>
#define _DEBUG (1)
#define DEBUG_ON (1)
#define DEBUG_OFF (0)
#define DEBUG_FILENAME ("debuglog.dat")
FILE * debugFilePtr;
DEBUG( int boolSwitchFlag)
{
if (boolSwitchFlag==DEBUG_ON)
{
debugFilePtr = fopen(DEBUG_FILENAME,"w+");
}
if (boolSwitchFlag==DEBUG_OFF)
{
fclose(debugFilePtr);
}
}
// optionally, you can display date/time stamp with debug messages
#define DEBUG_LOG(str) (fprintf(debugFilePtr,str))
/********** end of debug.h *****************/
int main()
{
DEBUG(DEBUG_ON);
int iLoop=0;
char debugBuff[255];
for (iLoop=0; iLoop<10; iLoop++)
{
#ifdef _DEBUG
sprintf(debugBuff," Loop counter iLoop = %d \n",iLoop);
DEBUG_LOG(debugBuff);
#endif
printf(" Loop counter iLoop = %d \n",iLoop);
}
DEBUG(DEBUG_OFF);
}