#include <stdio.h>
#include <conio.h>
#define GRID_X 30
#define GRID_Y 20
unsigned char board[GRID_Y][GRID_X];
void draw_board( unsigned char ** );
void print_board( unsigned char ** );
int main()
{
draw_board( board );
getch();
return 0;
}
void draw_board( unsigned char **board )
{
unsigned int r_itr = 0,
c_itr = 0;
if( NULL == board )
{
printf( "cannot create board..!!" );
exit(0);
}
r_itr = 0;
for( c_itr = 0; c_itr < GRID_X; ++c_itr )
{
board[ r_itr ][ c_itr ] = '+'; /* <- crashing here */
board[ r_itr + ( GRID_Y-1 ) ][ c_itr ] = '+';
}
c_itr = 0;
for( r_itr = 0; r_itr < GRID_Y; ++r_itr )
{
board[r_itr][c_itr] = '+';
board[ r_itr ][ c_itr + GRID_X-1 ] = '+';
}
print_board( board );
}
void print_board( unsigned char **board )
{
int r = 0,
c = 0;
for( r = 0; r < GRID_Y; ++r )
{
for( c = 0; c < GRID_X; ++c )
{
printf( "%c", board[r][c] );
}
printf("\n");
}
}
The above code is crashing at the point I mentioned via comment ( crashing here ). I did all the possible boundary-checking ( based on my understanding ), I am still not able to detect the reason for crashing? I used GNU GCC compiler and code blocks IDE.please help?