私はすべてを試しましたが、私が理解したところでは、このコードは正しいですが、それでも私のセグメンテーションフォルトが得られます。助けて?動的多次元配列
#include <stdio.h>
#include<malloc.h>
void da(int ***array, int row, int col){
int i;
*array=(int **)malloc(sizeof(int *)*row);
for (i=0; i<row; i++)
*array[i]=(int *)malloc(sizeof(int)*col);
}
main(){
int **array;
int i,n,m;
printf("Input number of rows: ");
scanf("%d",&n);
printf("Input number of columns: ");
scanf("%d",&m);
da(&array,n,m);
for (i=0; i<n; i++)
free(array[i]);
free(array);
}
どこが違うのですか?あなたはそれを修正するためにこれまでに何を試みましたか? –
'malloc'の戻り値をキャストしないでください。キャスティングは最高で重複しています(**あなたのコード**のように)エラーを隠すかもしれません。 *つまり、 'malloc'が宣言されているヘッダーをインクルードしないと、コンパイラは' void * 'の代わりに' int'を返します。 – pmg