I\'m translating some MATLAB code into C and the script I\'m converting makes heavy use of 3D arrays with 10*100*300 complex entries. The size of the array also depends on t
About the segfault, I am pretty sure someone else has pointed this out but just in case, there is a extra '*' in the first line of the first for loop
for (i = 0; i < 3; i++) {
*array[i] = malloc(3*sizeof(int*));
// ^ we dont want to deference array twice
for (j = 0; j < 3; j++) {
array[i][j] = malloc(3*sizeof(int));
}
}
try the following:
for (i = 0; i < 3; i++) {
array[i] = malloc(3*sizeof(int*));
for (j = 0; j < 3; j++) {
array[i][j] = malloc(3*sizeof(int));
}
}