I have this function to allocate memory to a matrix:
double **mmalloc(int r, int c){
double **matrix = (double **)malloc((r)*sizeof(double*));
for (int y = 0; y < r; y++){
matrix[y] = (double *)malloc(c*sizeof(double));
}
for (int y = 0; y < r; y++){
for(int x = 0; x < c; x++){
matrix[y][x] = 0;
}
}
return matrix;
}
How would I free all the memory of the returned matrix? I have this function to free the matrix... I can free the rows of the matrix but I cant free the columns.
Here's the freeing function:
// Free all memory allocated for A
void mfree(int r, int c, double **A){
for (int y = 0; y < r; y++){
free(A[y]);
}
}