[Debutant] Matrice dynamique
Bonsoir,
Voilà, j'essaie de crée une matrice dynamique, pour celà j'utilise plusieurs fonctions. Voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
void supprimer_mat(char** mat, int c) {
for(int i=0; i<c; i++)
delete mat[i];
delete [] mat;
}
void creer_mat(char** mat, int c, int l) {
mat = new char* [c];
for (int i=0; i<c; ++i)
mat[i] = new char[l];
}
void charge(int& l, int &c, char** mat) {
l=10, c=15;
creer_mat(mat, c, l);
for (int i=0; i<c; ++i)
for (int j=0; j<l; ++j)
mat[i][j] = 'a';
}
int main() {
int l,c;
char** mat = NULL;
charge(l, c, mat);
} |
Cependant il me met une erreur de segmentation (core dump).
Avez-vous une idée d'où cela puisse venir ?
Merci d'avance.