Hey all.
I am trying to make the minesweeper game, but I have one big problem that prevents me of continuing on my nearly finished project.
I cannot make the game run in turns. Everything runs exactly as I want it to the very first round, but after I input the coordinates of which tile to open in the second round, it crashes. It gives me the following error:
Code:
Debug Assertion Failed!
Program: {path}\minesweeper.exe
File: fprintf.c
Line: 55
Expression: (str != NULL)
I click on "Retry" to Debug, and get another window:
Code:
minesweeper.exe has triggered a breakpoint
It then shows me the line it supposedly breaks. The break point vary sometimes depending on my input, but usually it gives me the line I have marked in red.
You are reminded that this does NOT happen the first time the code is run, but only on the 2nd round.
Please help!
Code:
// SAVING DISPLAY DATA TO FILE
// TRANSFERRING DATA FROM MinesFile TO DisplayFile.
MinesFile = fopen("MinesFile.txt","r");
DisplayFile = fopen("DisplayFile.txt","w+");
for (i=0;i<dimX;i++)
{
for (j=0;j<dimY;j++)
{
ch = fgetc(MinesFile);
if ((ch == '0') || (ch == '1'))
{
fprintf(DisplayFile,"#");
}
else if (ch == '2')
{
count = check4Neighbours(dimY,dimX,i,j);
if (count == 0)
{
fprintf(DisplayFile,".");
}
else
{
fprintf(DisplayFile,"%d",count);
}
}
}
}
fclose(DisplayFile);
fclose(MinesFile);