I'm trying to manage 4D dynamic-allocated array. The code in the else statement give me the error. If I don't include the else statement, the code goes right, but is this a good practice?
int**** datind = (int****) malloc(nRow * sizeof(int***));
for (size_t i = 0; i < nRow; i++) {
    datind[i] = (int***) malloc(nCol * sizeof(int**));
}
for (size_t i = 0; i < nCol; i++) {
    for (size_t j = 0; j < nRow; j++) {
        datind[j][i] = (int**) malloc(1 * sizeof(int*));
    }
}
while ( fscanf(fp1, "%d %*c %d %*c %zu", &row, &col, &n_value) != EOF ) {
    if (n_value > 0) {
       datind[row-1][col-1] = (int**) realloc(datind[row-1][col-1], n_value * sizeof(int*));
       for (size_t i = 0; i < n_value; i++) {
           datind[row-1][col-1][i] = (int*) realloc(datind[row-1][col-1][i], 6 * sizeof(int));
           for (size_t j = 0; j < 6; j++) {
               fscanf(fp1,"%d%*c", &datind[row-1][col-1][i][j] );
           }
    } else {
       datind[row-1][col-1][0] = (int*) realloc(datind[row-1][col-1][0], 1 * sizeof(int));
       datind[row-1][col-1][0][0] = -1;
    }
}
Similar code for 3D array, i.e starting with int***, works well.
