diff --git a/correcteur.c b/correcteur.c index af84725..9a0f8a5 100644 --- a/correcteur.c +++ b/correcteur.c @@ -4,7 +4,7 @@ #include #define MAX_LETTRES 30 -#define size 26 +#define size 255 typedef struct node { @@ -64,19 +64,20 @@ void ajout(Node **N, char lettre) void ajout_alphab(Node ** pn, char * mot,int cpt) { Node * tmp= *pn; - //printf("%d \n",cpt); char lettre=mot[cpt]; - int pos = lettre - 'a'; - //printf("%c \n",lettre); - 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'){ (*tmp).fin_de_mot=1; return; } if (tmp->lettres[pos] == NULL) { - //printf("Rentré \n"); ajout(&tmp->lettres[pos],lettre); } + cpt++; return ajout_alphab(&tmp->lettres[pos],mot,cpt); @@ -90,7 +91,7 @@ void ajout_alphab(Node ** pn, char * mot,int cpt) Node * charger_arbre(Node ** Arbre){ FILE * dico; char mot[MAX_LETTRES]; - dico = fopen("test.txt","r"); + dico = fopen("words.txt","r"); int i; while ((i = fscanf(dico,"%s",mot)) == 1){ ajout_alphab(Arbre,mot,0); @@ -143,6 +144,7 @@ void detruire_arbre(Node ** Arbre) void initialisation(Node ** Arbre){ Node *nouveau = malloc(sizeof(struct node)); (*nouveau).l='?'; + (*nouveau).fin_de_mot=0; for (int i=0; ilettres[i] = NULL; *Arbre = nouveau;} @@ -151,29 +153,31 @@ void initialisation(Node ** Arbre){ -void comparaison(Node ** pn, char * mot,int cpt) +void comparaison(Node ** pn, char * mot,int cpt) { char lettre=mot[cpt]; - int pos = lettre - 'a'; + int pos = lettre ; cpt++; if (lettre == '\0'){ - if((*pn).fin_de_mot=0) printf("erreur \n"); - return; + if((*pn)->fin_de_mot==0){ + printf("1 erreur \n"); + } + + return ; } - if (tmp->lettres[pos] == NULL) { - printf("erreur \n"); + if ((*pn)->lettres[pos] == NULL) { + printf("1 erreur \n"); + return; } - return comparaison(&pn->lettres[pos],mot,cpt); + return comparaison(&(*pn)->lettres[pos],mot,cpt); } -void test_erreur(){ - Node * Dico; - charger_arbre(&Dico); +void test_erreur(Node * Dico){ FILE * texte; char mot[MAX_LETTRES]; - texte = fopen("texte.txt","r"); + texte = fopen("test.txt","r"); int i; while ((i = fscanf(texte,"%s",mot)) == 1){ comparaison(&Dico,mot,0); @@ -192,8 +196,9 @@ int main(){ charger_arbre(&Arbre); affichage_arbre(Arbre); printf("Arbre fini \n"); + test_erreur(Arbre); detruire_arbre(&Arbre); - affichage_arbre(Arbre); - test_erreur(); + //affichage_arbre(Arbre); + return 0; } -- libgit2 0.21.2