I have this functions:
char** init_matrix(int rows, int columns){
char **matrix = (char **)malloc (rows*sizeof(char *));
for(int i = 0; i < rows; i++){
matrix[i] = (char *) malloc (columns*sizeof(char));
for(int j = 0; j < columns; j++){
matrix[i][j] = '-';
}
}
return matrix;
}
void show_matrix(char **matrix, int rows, int columns){
printf("\n\n");
for(int i = 0; i < rows; i++) {
for(int j = 0; j < columns; j++)
printf("|%c|", matrix[i][j]);
printf("\n");
for(int j = 0; j < columns; j++)
printf("---");
printf("\n");
}
}
void setValueInMatrix(char** matrix, int row, int column, char value){
matrix[row][column] = value;
}
Then i do this
char **matrix = init_matrix(rows, columns);
setValueInMatrix(matrix, solucion->row, solucion->column, solucion->aminoacido);
printf("matrix before free\n");
show_matrix(matrix, rows, columns);
for(int i = 0; i < rows; i++){
free(matrix[i]);
}
free(matrix);
printf("matrix after free\n");
show_matrix(matrix, rows, columns);
Why the output is the same before and after the free?? :S
Output:
matrix before free
|-||-||-||H||-||-||-|
---------------------
|-||-||-||P||-||-||-|
---------------------
|-||-||-||P||-||-||-|
---------------------
|-||-||-||H||-||-||-|
---------------------
|-||-||-||-||-||-||-|
---------------------
|-||-||-||-||-||-||-|
---------------------
|-||-||-||-||-||-||-|
---------------------
matrix after free
|-||-||-||H||-||-||-|
---------------------
|-||-||-||P||-||-||-|
---------------------
|-||-||-||P||-||-||-|
---------------------
|-||-||-||H||-||-||-|
---------------------
|-||-||-||-||-||-||-|
---------------------
|-||-||-||-||-||-||-|
---------------------
|-||-||-||-||-||-||-|
---------------------
I have read all this posts but it doesnt look like it works: