I tried everything and from what I understood, this code is correct but it still gives my Segmentation Fault. Help?
#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. Casting is, at best, redundant and (as in your code) may hide errors; namely the failure to include the header wheremallocis declared making the compiler assume the return type isintinstead ofvoid*.