This commit is contained in:
2026-02-09 03:43:16 +01:00
parent 5082f62e59
commit d6eecf0cee
8 changed files with 143 additions and 20 deletions
+7 -2
View File
@@ -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;
}