diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-11-21 18:37:48 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-11-21 18:37:48 +0100 |
| commit | 20fc727d4f954eb2109b71a7686c3107fdfa4bbf (patch) | |
| tree | a5613db97e67d8968c7d622b605ed530755176bb /semestre 3/structures des données/tme/tme6-11/Chaine.c | |
| parent | 341fc63ff791e08c7d0a00346080067c9bd1d5dd (diff) | |
Cours du 3 au 21 novembre
ce qui fait 3 semaines en philo et une semaine en info
Diffstat (limited to 'semestre 3/structures des données/tme/tme6-11/Chaine.c')
| -rw-r--r-- | semestre 3/structures des données/tme/tme6-11/Chaine.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/semestre 3/structures des données/tme/tme6-11/Chaine.c b/semestre 3/structures des données/tme/tme6-11/Chaine.c new file mode 100644 index 0000000..d25f38e --- /dev/null +++ b/semestre 3/structures des données/tme/tme6-11/Chaine.c @@ -0,0 +1,54 @@ +#include "Chaine.h" +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +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; + } +} |
