Wish to populate a 2D array using pointers
Hi,
Last night I had a go at populating a 2D 8x8 array using pointers - I want to use pointers as a memory exercise. From memory this is what I had:
Code:
int main()
{
char gameGrid[8][8];
/* I just want to understand how to pass the grid as reference and fill in using pointers */
initialGrid( gameGrid, 8, 8); /* I will be remove hard coding later*/
}
void initialGrid(char *grid, int colsize, rowsize)
{
int i,j
for (i=0; i<colsize; i++)
for (j=0; j<rowsize; j++, grid++)
*grid[i][j] = '.'; <---- I believe this is wrong.
printf("\n\nGrid initialised with dots");
}
I can compile successfully using gcc under Mandrake linux. Running gives me a segmentation fault. I am not sure what is the issue? I suspect it is the way I am trying to populate the gird. Apologies if any syntax is wrong but I'm at work(sql) right now.
Any pointers (sic) to where I am falling over? :)