From 20fc727d4f954eb2109b71a7686c3107fdfa4bbf Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Fri, 21 Nov 2025 18:37:48 +0100 Subject: Cours du 3 au 21 novembre ce qui fait 3 semaines en philo et une semaine en info --- .../tme/tme6-11/Chaine.c" | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "semestre 3/structures des donn\303\251es/tme/tme6-11/Chaine.c" (limited to 'semestre 3/structures des données/tme/tme6-11/Chaine.c') diff --git "a/semestre 3/structures des donn\303\251es/tme/tme6-11/Chaine.c" "b/semestre 3/structures des donn\303\251es/tme/tme6-11/Chaine.c" new file mode 100644 index 0000000..d25f38e --- /dev/null +++ "b/semestre 3/structures des donn\303\251es/tme/tme6-11/Chaine.c" @@ -0,0 +1,54 @@ +#include "Chaine.h" +#include +#include +#include + +Chaines* lectureChaines(FILE* f){ + char s[256]; + char* err = fgets(s, 256, f); + if (!err) return NULL; + int nbChain; + sscanf(s, "NbChain: %d", &nbChain); + + err = fgets(s, 256, f); + if (!err) return NULL; + int gamma; + sscanf(s, "Gamma: %d", &gamma); + + Chaines* chains = (Chaines*) malloc(sizeof(Chaines)); + chains->nbChaines = nbChain; + chains->gamma = gamma; + + for (int i = 0; i < nbChain; i++){ + err = fgets(s, 256, f); + if (!err) { + free(chains); // avoiding a memory leak + return NULL; + } + CellChaine* chain = (CellChaine*) malloc(sizeof(CellChaine)); + chain->points = NULL; + chain->suiv = chains->chaines; + chains->chaines = chain; + int nbPoints; + sscanf(s, "%d %d %s", &chain->numero, &nbPoints, s); + for (int j = 0; j < nbPoints; j++){ + CellPoint* point = (CellPoint*) malloc(sizeof(CellPoint)); + point->suiv = chain->points; + chain->points = point; + if (j < nbPoints-1) sscanf(s, "%lf %lf %s", &point->x, &point->y, s); + else sscanf(s, "%lf %lf", &point->x, &point->y); + } + } + return chains; +} + +void ecrireChaines(Chaines* c, FILE* f){ + fprintf(f, "NbChain: %d\n", c->nbChaines); + fprintf(f, "Gamma: %d\n", c->gamma); + CellChaine** chains = (CellChaine**) malloc(sizeof(CellChaine)*c->nbChaines); + CellChaine* chain = c->chaines; + for (int i = 0; i < c->nbChaines; i++){ + chains[i - c->nbChaines - 1] = chain; + chain = chain->suiv; + } +} -- cgit v1.2.3