プロシージャへのポインタへのポインタを渡そうとしていますが、関数に渡すと完全に正常に動作しますが、毎回セグメンテーション違反が発生します。この質問のように、 C がポインターへの配列に対して自動的に行う強制と関係があると思います: C のポインターにポインターを渡します。
しかし、私はそれを修正する方法がわかりません。
コードは次のとおりです。
#include <stdio.h>
#include <stdlib.h>
void creer_matrice(int nbCol, int nbLigne, char **matrice)
{
int i,j;
matrice = calloc( nbCol, sizeof(char*));
if( matrice == NULL ){
printf("Allocation impossible");
exit(EXIT_FAILURE);
}
for( i = 0 ; i < nbLigne ; i++ ){
matrice[i] = calloc (nbCol, sizeof(char*));
if( matrice[i] == NULL ){
printf("Allocation impossible");
exit(EXIT_FAILURE);
}
}
/* Remplissage de test*/
for(i = 0; i < nbLigne; i++){
for(j = 0; j < nbCol; j++){
matrice[i][j] = 'I';
}
}
//return matrice;
}
int main(){
int i,j;
char **matrice;
creer_matrice(8,6,matrice);
//matrice = creer_matrice(8,6);
for(i = 0; i < 6; i++){
for(j = 0; j < 8; j++){
printf("%c ",matrice[i][j]);
}
printf("\n");
}
}
誰かが私が間違っている場所とそれを解決する方法を教えてもらえますか?