Hi, I'm writing a small game, now figuring how to set up the game board. This code creates an area in which the game will be played.. Now, when I change the X or Y it shows no error, though when I run it an exception is generated. I guess it's something to do with referring outside my table, but can't see it.
So, here's the code:
Code:
#include <stdio.h>
#define X 20
#define Y 20
int main (void)
{
char table [X][Y] = {' '};
int i, j;
for (i=0;i<Y;i++)
{
table[0][i] = 'O';
}
for (i=0;i<Y;i++)
{
table[Y-1][i] = 'O';
}
for (i=0;i<X;i++)
{
table[i][0] = 'O';
}
for (i=0;i<X;i++)
{
table[i][X-1] = 'O';
}
for (i=0;i<Y;i++)
{
for (j=0;j<X;j++)
{
printf("%c", table[i][j]);
}
printf("\n");
}
return 0;
}