From 7845acce33cee0af96250c40e6ea9680589bf1b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Wed, 10 Jan 2024 09:13:38 +0100 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20et=20allocation=20du=20tableau?= =?UTF-8?q?=20des=20T=C3=A2ches?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/precedences.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/precedences.c diff --git a/src/precedences.c b/src/precedences.c new file mode 100644 index 0000000..1c220c2 --- /dev/null +++ b/src/precedences.c @@ -0,0 +1,46 @@ +/** + * @file precedences.c + * @brief Gestion des tâches et leurs précédences +*/ + +#include "specification1.h" + +/** + * @brief Créer un tableau dynamique de structures Tache et de taille nbTaches + * @param nbTaches Nombre de tâches à créer + * @return Un tableau de pointeurs vers des structures Tache +*/ +Tache** creerTabTache(int nbTaches) +{ + Tache** tabTaches; + tabTaches = (Tache**)malloc(nbTaches * sizeof(Tache*)); + + if (tabTaches == NULL) + { + printf("[ERREUR] - Problème d'allocation mémoire.\n"); + exit(1); + } + + for (int i = 0; i < nbTaches; i++) + { + tabTaches[i] = (Tache*)malloc(sizeof(Tache)); + } + + return tabTaches; +} + +/** + * @brief Libère la mémoire allouée pour le tableau de tâches + * @param nbTaches Nombre de tâches à libérer dans le tableau + * @param tabTaches Tableau de tâches à libérer + * @return void +*/ +void freeTabTache(int nbTaches, Tache** tabTaches) +{ + for (int i = 0; i < nbTaches; i++) + { + free(tabTaches[i]); + } + + free(tabTaches); +} \ No newline at end of file