diff --git a/correcteur.c b/correcteur.c index 94e38c1..af84725 100644 --- a/correcteur.c +++ b/correcteur.c @@ -90,7 +90,7 @@ void ajout_alphab(Node ** pn, char * mot,int cpt) Node * charger_arbre(Node ** Arbre){ FILE * dico; char mot[MAX_LETTRES]; - dico = fopen("text.txt","r"); + dico = fopen("test.txt","r"); int i; while ((i = fscanf(dico,"%s",mot)) == 1){ ajout_alphab(Arbre,mot,0); @@ -106,7 +106,7 @@ Node * charger_arbre(Node ** Arbre){ void affichage_arbre(Node * Arbre) { - if (Arbre->l == '?' && is_leaf(Arbre)){ + if (is_empty(Arbre)){ printf("arbre vide \n"); return; } @@ -126,16 +126,13 @@ void affichage_arbre(Node * Arbre) void detruire_arbre(Node ** Arbre) { - printf("---------- \n"); - printf("%p \n",*Arbre); + if (is_empty(*Arbre)) return; - printf("%c \n",(*Arbre)->l); for (int i=0; ilettres[i]); } free(*Arbre); - printf("suppression \n"); - printf("%p \n",*Arbre); + *Arbre=NULL; } @@ -147,10 +144,45 @@ void initialisation(Node ** Arbre){ Node *nouveau = malloc(sizeof(struct node)); (*nouveau).l='?'; for (int i=0; ilettres[i] = NULL; - *Arbre = nouveau; + *Arbre = nouveau;} + + + + + + +void comparaison(Node ** pn, char * mot,int cpt) +{ + char lettre=mot[cpt]; + int pos = lettre - 'a'; + cpt++; + if (lettre == '\0'){ + if((*pn).fin_de_mot=0) printf("erreur \n"); + return; + } + if (tmp->lettres[pos] == NULL) { + printf("erreur \n"); + } + return comparaison(&pn->lettres[pos],mot,cpt); + + +} + +void test_erreur(){ + Node * Dico; + charger_arbre(&Dico); + FILE * texte; + char mot[MAX_LETTRES]; + texte = fopen("texte.txt","r"); + int i; + while ((i = fscanf(texte,"%s",mot)) == 1){ + comparaison(&Dico,mot,0); + } + fclose(texte); } + @@ -162,5 +194,6 @@ int main(){ printf("Arbre fini \n"); detruire_arbre(&Arbre); affichage_arbre(Arbre); + test_erreur(); return 0; } -- libgit2 0.21.2