(Chars) Dynamic array allocation and assignment

I'm allocating memory for a 8X8 char array:

1
2
3
4
char **game;
game = (char**)malloc(8 * sizeof(char*));
for(i = 0; i < 8; i++)
   game[i] = (char*)malloc(8 * sizeof(char));     


then try to assign a character from a char array to each column in the first row
game[0][0] = r, game[0][1] = b and so on...

1
2
3
4
char myArray[8] = "rbnqknbr";
i=0;
for(int j=0; j<8; j++)
   game[i][j] = myArray[j];


Code compiles with no errors but the cmd line crashes when I run the program. Any thoughts?
The "malloc()" function is a leftover from C, one that I personally would like to see buried and never heard from again. The new operator is much nicer looking when writting C++: http://www.cplusplus.com/doc/tutorial/dynamic/

yeah, sorry guys I guess I'm in the wrong forum. I'm asking for C help. :)
Last edited on
Topic archived. No new replies allowed.