allocation dynamique matrices
Bonjour,
J'essaye d'allouer dynamiquement en mémoire un Labyrinthe 3D contenu de rangées, colonnes et plateaux.
Chaque case peut être un mur, un passage, un dragon ou un trésor :
Code:
enum typeCase { MUR , PASSAGE , DRAGON , TRESOR };
Mon labyrinthe est défini comme ceci :
Code:
typedef typeCase Lab
et
voici ce que j'ai déja fait pour la fonction d'allocation :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| Lab*** alloc_lab(Lab*** lab, const Format f) {
// Allocation du labyrinthe entier
lab = (Lab***) malloc( sizeof(Lab)*(f.nbMatrix*f.row*f.colomn) );
// Allocation des matrices
for(unsigned int i=0;i<f.nbMatrix;i++) {
lab[i] = (Lab**) malloc ( sizeof(Lab)*(f.row*f.colomn) );
// Allocation des colonnes
for(unsigned int j=0; j<f.row; j++)
lab[i][j] = (Lab*) malloc ( sizeof(Lab)*f.colomn );
}
return lab;
} |
Faut-il que j'alloue aussi les rangées ?