I have a typedef setup like this:
typedef struct character {
int level;
int jobLevel;
int health;
int healthMax;
char *name;
} player;
Using this def, I initialize "player currentPlayer;". The various attributes are set. Later on in the game, I wish to export this to a text document for debugging purposes. Here's what I did:
char szTemp[38];
FILE *pFile=fopen("characterDetails.txt","w");
if(pFile!=NULL){
sprintf(szTemp,"Character Name: %sn",currentPlayer.name);fputs(szTemp,pFile);fflush(pFile);
sprintf(szTemp,"Level/Joblevel: %d / %dn",currentPlayer.level,currentPlayer.jobLevel);fputs(szTemp,pFile);fflush(pFile);
sprintf(szTemp,"Health/Max: %d / %dn",currentPlayer.health,currentPlayer.healthMax);fputs(szTemp,pFile);fflush(pFile);
fclose(pFile);
}
else{
MessageBox(g_pGlob->hWnd,"File create/open failed!","Attention",MB_OK);
}
When run in release mode, this code halts, with VC++ giving the following error:
Unhandled exception at 0x0042f199 in LeafRPG.exe: 0xC0000005: Access violation reading location 0x6f666562.
Break/Continue buttons on a message box containing this error are presented. If I hit continue, the same unhandled exception occurs.
When building in debug mode, this exception isn't present, however a buffer overrun is reported when the application closes, which I've traced back to using strcmp().
*EDIT: The buffer overrun was NOT caused by strcmp(), and I do not know what is causing it. Full source available if necessary.
**FIX: Problem resolved. Related to buffering string 'szTemp'. By initializing the string globally before all includes, all issues were resolved. Although technically it should not have been a problem, this is a solid fix.
My site, for various stuff that I make.