I'm trying to figure out why this program crashes sometimes but then runs successfully other times. The program initializes a 2d char array in a grid pattern and then prints it out. It seems to crash every other time I run it. Anyone have any ideas to what might be wrong with it?
You have the x and y mixed up in the for loops of the functions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
void resetGrid(char grid[][51])
{
for(int y=0;y<21;y++)// The 'y' in the array is 51,
{
for(int x=0;x<51;x++)// and 'x' to 21
{
if(x%5==0 && y%5==0)
grid[x][y]='+';// The 'y' in the array is 51, and 'x' to 21
elseif(x%5!=0 && y%5==0)
grid[x][y]='-';
elseif(x%5==0 && y%5!=0)
grid[x][y]='|';
else
grid[x][y]=' ';
}
}
}
Change them around in both functions, and it works perfectly