Dynamic char array allocation and assignment
I'm allocating memory for a 8X8 char array:
Code:
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...
Code:
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?