void matrixSetSize(double ***pMatrix, int size) {
if (*pMatrix == NULL) { // void matrix
*pMatrix = (double**)malloc(size * sizeof(double*));
for (int i = 0; i < size; i++)
*(*pMatrix + i) = (double*)malloc(size * sizeof(double));
}
else { // resize existing matrix
double **pointer = (double**)realloc(*pMatrix, 2 * size * sizeof(double*));
for(int i = 0; i < size; i++)
pointer[i] = (double*)realloc(*(pMatrix+i), 2 * size * sizeof(double));
for (int i = size; i < 2 * size; i++)
pointer[i] = (double*)malloc(size * sizeof(double));
for(int i = 0; i < size; i++)
free(*(*pMatrix + i));
free(*pMatrix);
*pMatrix = pointer;
}
}
Problem: When I try to realocate the size of the matrix, the code won't work and I don't know why. Can someone explain to me why isn't working?