From 0aa091e733d47f2884ba5d33b25a634b96c0750d Mon Sep 17 00:00:00 2001 From: Fontaine Maxime Date: Tue, 30 Apr 2019 14:17:29 +0200 Subject: [PATCH] Algorithme modifié --- correcteur.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/correcteur.c b/correcteur.c index 9a0f8a5..4485249 100644 --- a/correcteur.c +++ b/correcteur.c @@ -66,11 +66,10 @@ void ajout_alphab(Node ** pn, char * mot,int cpt) Node * tmp= *pn; char lettre=mot[cpt]; int pos; - /*if (lettre>=97 && lettre<=122) pos = lettre - 'a'; - if (lettre == 39) pos=26; - if (lettre>='A' && lettre <= 'Z') pos =lettre -'A';*/ + pos=lettre; - if (lettre == '\0'){ + if (lettre>='A' && lettre <= 'Z') pos =lettre -'A'+'a'; + if (lettre == '\0' || pos == 44 || pos == 46){ (*tmp).fin_de_mot=1; return; } @@ -153,35 +152,41 @@ void initialisation(Node ** Arbre){ -void comparaison(Node ** pn, char * mot,int cpt) +int comparaison(Node ** pn, char * mot,int cpt,int * erreur) { char lettre=mot[cpt]; int pos = lettre ; + if (lettre>='A' && lettre <= 'Z') pos =lettre -'A'+'a'; cpt++; - if (lettre == '\0'){ + if (lettre == '\0' || pos == 44 || pos == 46){ if((*pn)->fin_de_mot==0){ - printf("1 erreur \n"); + (*erreur)++; } - return ; + return (*erreur); } + if (lettre == '?' || lettre == '!' || lettre == ':' || lettre == ';') return 0; if ((*pn)->lettres[pos] == NULL) { - printf("1 erreur \n"); - return; + (*erreur)++; + return (*erreur); } - return comparaison(&(*pn)->lettres[pos],mot,cpt); + return comparaison(&(*pn)->lettres[pos],mot,cpt,erreur); } void test_erreur(Node * Dico){ FILE * texte; + int * erreur=malloc(sizeof(int)); + (*erreur)=0; char mot[MAX_LETTRES]; texte = fopen("test.txt","r"); int i; while ((i = fscanf(texte,"%s",mot)) == 1){ - comparaison(&Dico,mot,0); + (*erreur)=comparaison(&Dico,mot,0,erreur); } + if ((*erreur)==0 || (*erreur)==1 ) printf("%d erreur",(*erreur)); + else printf("%d erreurs",(*erreur)); fclose(texte); } @@ -194,7 +199,7 @@ int main(){ Node * Arbre; initialisation(&Arbre); charger_arbre(&Arbre); - affichage_arbre(Arbre); + //affichage_arbre(Arbre); printf("Arbre fini \n"); test_erreur(Arbre); detruire_arbre(&Arbre); -- libgit2 0.21.2