Commit 0aa091e733d47f2884ba5d33b25a634b96c0750d

Authored by Fontaine Maxime
1 parent ef5eea94

Algorithme modifié

Showing 1 changed file with 18 additions and 13 deletions   Show diff stats
@@ -66,11 +66,10 @@ void ajout_alphab(Node ** pn, char * mot,int cpt) @@ -66,11 +66,10 @@ void ajout_alphab(Node ** pn, char * mot,int cpt)
66 Node * tmp= *pn; 66 Node * tmp= *pn;
67 char lettre=mot[cpt]; 67 char lettre=mot[cpt];
68 int pos; 68 int pos;
69 - /*if (lettre>=97 && lettre<=122) pos = lettre - 'a';  
70 - if (lettre == 39) pos=26;  
71 - if (lettre>='A' && lettre <= 'Z') pos =lettre -'A';*/ 69 +
72 pos=lettre; 70 pos=lettre;
73 - if (lettre == '\0'){ 71 + if (lettre>='A' && lettre <= 'Z') pos =lettre -'A'+'a';
  72 + if (lettre == '\0' || pos == 44 || pos == 46){
74 (*tmp).fin_de_mot=1; 73 (*tmp).fin_de_mot=1;
75 return; 74 return;
76 } 75 }
@@ -153,35 +152,41 @@ void initialisation(Node ** Arbre){ @@ -153,35 +152,41 @@ void initialisation(Node ** Arbre){
153 152
154 153
155 154
156 -void comparaison(Node ** pn, char * mot,int cpt) 155 +int comparaison(Node ** pn, char * mot,int cpt,int * erreur)
157 { 156 {
158 char lettre=mot[cpt]; 157 char lettre=mot[cpt];
159 int pos = lettre ; 158 int pos = lettre ;
  159 + if (lettre>='A' && lettre <= 'Z') pos =lettre -'A'+'a';
160 cpt++; 160 cpt++;
161 - if (lettre == '\0'){ 161 + if (lettre == '\0' || pos == 44 || pos == 46){
162 if((*pn)->fin_de_mot==0){ 162 if((*pn)->fin_de_mot==0){
163 - printf("1 erreur \n"); 163 + (*erreur)++;
164 } 164 }
165 165
166 - return ; 166 + return (*erreur);
167 } 167 }
  168 + if (lettre == '?' || lettre == '!' || lettre == ':' || lettre == ';') return 0;
168 if ((*pn)->lettres[pos] == NULL) { 169 if ((*pn)->lettres[pos] == NULL) {
169 - printf("1 erreur \n");  
170 - return; 170 + (*erreur)++;
  171 + return (*erreur);
171 } 172 }
172 - return comparaison(&(*pn)->lettres[pos],mot,cpt); 173 + return comparaison(&(*pn)->lettres[pos],mot,cpt,erreur);
173 174
174 175
175 } 176 }
176 177
177 void test_erreur(Node * Dico){ 178 void test_erreur(Node * Dico){
178 FILE * texte; 179 FILE * texte;
  180 + int * erreur=malloc(sizeof(int));
  181 + (*erreur)=0;
179 char mot[MAX_LETTRES]; 182 char mot[MAX_LETTRES];
180 texte = fopen("test.txt","r"); 183 texte = fopen("test.txt","r");
181 int i; 184 int i;
182 while ((i = fscanf(texte,"%s",mot)) == 1){ 185 while ((i = fscanf(texte,"%s",mot)) == 1){
183 - comparaison(&Dico,mot,0); 186 + (*erreur)=comparaison(&Dico,mot,0,erreur);
184 } 187 }
  188 + if ((*erreur)==0 || (*erreur)==1 ) printf("%d erreur",(*erreur));
  189 + else printf("%d erreurs",(*erreur));
185 fclose(texte); 190 fclose(texte);
186 } 191 }
187 192
@@ -194,7 +199,7 @@ int main(){ @@ -194,7 +199,7 @@ int main(){
194 Node * Arbre; 199 Node * Arbre;
195 initialisation(&Arbre); 200 initialisation(&Arbre);
196 charger_arbre(&Arbre); 201 charger_arbre(&Arbre);
197 - affichage_arbre(Arbre); 202 + //affichage_arbre(Arbre);
198 printf("Arbre fini \n"); 203 printf("Arbre fini \n");
199 test_erreur(Arbre); 204 test_erreur(Arbre);
200 detruire_arbre(&Arbre); 205 detruire_arbre(&Arbre);