I cannot find what's wrong in this simple array initialization.
The program crashes with a segfault on field[x][y] = ' ';
, x and y at 0 (I use Code::Blocks debugger)
/* init data structures */
char **field;
int field_width=5,field_height=5;
field = malloc(sizeof(char*)*field_width);
for(x=0;x<field_width;x++)
{
field[x] = malloc(sizeof(char)*field_height);
for(y=0;y<field_height;y++)
{
field[x][y] = ' ';
}
}
Any idea of what I am doing wrong ?