I need to allocate a char** array that points to a 2 dimensions chars array.
Eventually, I want to point to a "cell" like players[playerNum][Row][Col]
.
This is what I wrote so far, but it fails.
It is hard to understand the logic behind it, so if you can explain me whats wrong it will be great.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int numOfPlayers;
int i,j;
char** players = (char **)malloc(sizeof(char**)*numOfPlayers); // players array
for (i=0 ; i<numOfPlayers ; i++){
players[i] = (char *)malloc(sizeof(char*)*10); // each player 1st D array
}
for (i=0 ; i<10 ; i++){
for (j=0 ; j<10 ; j++){
players[i][j] = (char *)malloc(sizeof(char*)*10);
}
}
return 0;
}