eg
This commit is contained in:
@@ -3,12 +3,13 @@
|
||||
|
||||
int **allocate_matrix(int rows, int cols)
|
||||
{
|
||||
int **matrix = malloc(rows * sizeof(int *));
|
||||
int **matrix = malloc(rows * sizeof(int *));//creation du tableau X hauteur
|
||||
if (!matrix)
|
||||
return NULL;
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
matrix[i] = malloc(cols * sizeof(int));
|
||||
matrix[i] = malloc(cols * sizeof(int));//creation des colonnes
|
||||
//on free les cols si la matrice n'existe pas
|
||||
if (!matrix[i])
|
||||
{
|
||||
for (int j = 0; j < i; j++)
|
||||
@@ -24,6 +25,9 @@ void free_matrix(int **matrix, int rows)
|
||||
{
|
||||
if (!matrix)
|
||||
return;
|
||||
//ajout
|
||||
for (int j = 0; j < rows; j ++)
|
||||
free(matrix[j]);
|
||||
free(matrix);
|
||||
return;
|
||||
}
|
||||
@@ -47,5 +51,6 @@ int main(void)
|
||||
}
|
||||
|
||||
free_matrix(matrix, rows);
|
||||
//free(matrix);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user