diff --git a/TP/TP6/.listechaines.h.swp b/TP/TP6/.Makefile.un~ similarity index 54% rename from TP/TP6/.listechaines.h.swp rename to TP/TP6/.Makefile.un~ index 1ce58bd518c1500b271d104188f2bcec704d342b..02952405a2a83d08a63172828c7219e7380bc279 100644 Binary files a/TP/TP6/.listechaines.h.swp and b/TP/TP6/.Makefile.un~ differ diff --git a/TP/TP6/.listechaines.c.swp b/TP/TP6/.listechaines.c.swp deleted file mode 100644 index 8bb3f3aae090bd487b6a1620b0cf80bd643e2e38..0000000000000000000000000000000000000000 Binary files a/TP/TP6/.listechaines.c.swp and /dev/null differ diff --git a/TP/TP6/.listechaines.c.un~ b/TP/TP6/.listechaines.c.un~ index 84a2d9763b46dee2e435372713dcd6a0a07adc6a..db28349d8036e5d989cba7f032d31fd235c5776b 100644 Binary files a/TP/TP6/.listechaines.c.un~ and b/TP/TP6/.listechaines.c.un~ differ diff --git a/TP/TP6/.text.txt.un~ b/TP/TP6/.text.txt.un~ new file mode 100644 index 0000000000000000000000000000000000000000..2f7b571208df0273ccf912a45d843f42f69e909d Binary files /dev/null and b/TP/TP6/.text.txt.un~ differ diff --git a/TP/TP6/.tp6.c.un~ b/TP/TP6/.tp6.c.un~ new file mode 100644 index 0000000000000000000000000000000000000000..d11c22b827911ceb7838312127ed6d22f0b6f39e Binary files /dev/null and b/TP/TP6/.tp6.c.un~ differ diff --git a/TP/TP6/Makefile b/TP/TP6/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..3457a63326e43420653b9a7d25a5178bc5a99235 --- /dev/null +++ b/TP/TP6/Makefile @@ -0,0 +1,17 @@ + +TARGET=tp6 +CFLAGS=-g -W -Wall -Wextra + +default: $(TARGET) + +listechaines.o: listechaines.c listechaines.h + gcc $(CFLAGS) -c listechaines.c + +tp6.o : tp6.c listechaines.h + gcc $(CFLAGS) -c tp6.c + +$(TARGET): $(TARGET).o listechaines.o + gcc tp6.o listechaines.o -o $(TARGET) + +clean: + rm -f *.o *~ $(TARGET) diff --git a/TP/TP6/accompttp.c~ b/TP/TP6/accompttp.c~ deleted file mode 100644 index bd8359538fb0651bd02604da44468a084704205e..0000000000000000000000000000000000000000 --- a/TP/TP6/accompttp.c~ +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Acompagnement du TP, code exemple pour vous aider. -*/ - -//ajout d'un mot dans une liste chainee triée -void ajout_alphab(struct cell ** pl, char * mot) -{ - // liste vide ou mot < mot prochain => ajout en tête - if ( (*pl == NULL) || (strcmp(mot, (*pl)->val) < 0) ) - { - ajout_tete(pl,mot); - } - else - { - // mot > mot prochain => ajouter après dans la liste - if (strcmp(mot, (*pl)->val) > 0) - { - ajout_alphab(&(*pl)->suiv,mot); - } - //else => mot déjà dans la liste, ne rien faire? - } -} - - -//construit une liste triee a partir d'un fichier -void charge_fichier(FILE * fp, struct cell ** pl) -{ - char mot[MAXSIZE]; - - //Nb d'elements à lire dans chaque fscanf - const int NB_A_LIRE = 1; - - //`man fscanf` pour comprendre les valeurs de retour!!! - while (fscanf(fp, "%s", mot) == NB_A_LIRE) - { - ajout_alphab(pl, mot); - } - - //On peut tester la bonne ou mauvaise terminaison de la lecture - if(feof(fp)) printf("Fin normal de lecture\n"); - if(ferror(fp)) printf("ERREUR de lecture\n"); - -} diff --git a/TP/TP6/listechaines.c b/TP/TP6/listechaines.c index d0c2fa85847c17fa2b9633e101f092a490873521..704a7918fb82762f2606490711b7ad8cd5ff5bdb 100644 --- a/TP/TP6/listechaines.c +++ b/TP/TP6/listechaines.c @@ -1,3 +1,4 @@ +#include "listechaines.h" @@ -12,8 +13,8 @@ void afficher_liste(struct cell* liste){ printf("Voici la liste:\n"); while (temp != NULL){ - printf("%s\n", temp->c.val); - temp = temp->suivant; + printf("%s\n", temp->val); + temp = temp->suiv; } } @@ -28,15 +29,15 @@ void ajout_tete(struct cell **pliste, char *c){ } -int supp_tete(struct cell **pliste){ +void supp_tete(struct cell **pliste){ if (*pliste == NULL) - return 0; + return; struct cell *temp; temp = *pliste; - *pliste = (*pliste)->suivant; + *pliste = (*pliste)->suiv; free(temp); - return 1; + return; } @@ -87,17 +88,17 @@ void charge_fichier(FILE * fp, struct cell ** pl) bool appartient(struct cell *liste, char *c){ if (liste == NULL) return 0; if (!strcmp(liste->val,c)) return 1; - return (appartient(liste->suiv)); + return (appartient(liste->suiv,c)); } int taille(struct cell *liste){ if (liste == NULL) return 0; - return taille(liste->suiv)+1 + return taille(liste->suiv)+1; } -int main(){ + diff --git a/TP/TP6/listechaines.o b/TP/TP6/listechaines.o new file mode 100644 index 0000000000000000000000000000000000000000..a041c6c16dc8eb942914af577152237ade0801bb Binary files /dev/null and b/TP/TP6/listechaines.o differ diff --git a/TP/TP6/text.txt b/TP/TP6/text.txt new file mode 100644 index 0000000000000000000000000000000000000000..cc70431b54d341475330819a4be887bb12b8d2af --- /dev/null +++ b/TP/TP6/text.txt @@ -0,0 +1,14 @@ +Mathilde +Pauline +Paul +Edward +Kevin +Louis +Najet +Marine +Yoan +Liam +Arnaud +Janet +Georges +Benoit diff --git a/TP/TP6/tp6.c b/TP/TP6/tp6.c new file mode 100644 index 0000000000000000000000000000000000000000..fa3cfff65302ae5759e191efe6f0e2da413bc903 --- /dev/null +++ b/TP/TP6/tp6.c @@ -0,0 +1,23 @@ + +#include <stdio.h> +#include <stdlib.h> +#include "listechaines.h" +int main(){ + + struct cell *liste; + liste = NULL; + + FILE *fd; + fd = fopen("text.txt","r"); + + charge_fichier(fd,&liste); + afficher_liste(liste); + + fclose(fd); + + + + + return 0; +} + diff --git a/TP/TP6/tp6.o b/TP/TP6/tp6.o new file mode 100644 index 0000000000000000000000000000000000000000..8d68921a094cd19dc11e4a8ef7654fa9f3321bca Binary files /dev/null and b/TP/TP6/tp6.o differ