diff --git a/correcteur.c b/correcteur.c index ddc5006..29580f7 100644 --- a/correcteur.c +++ b/correcteur.c @@ -1,51 +1,58 @@ #include #include #include +#include -#DEFINE MAX_LETTRES 30 +#define MAX_LETTRES 30 typedef struct node { + char l; struct node * lettres[27]; bool fin_de_mot; int dernier; } Node; -void ajout_tete(Node **N, char * mot) +void ajout(Node **N, char mot) { - Cellule *nouveau = malloc(sizeof(struct node)); - strcpy(nouveau->(*N)->dernier, mot); - nouveau->suivant = *N; + Node *nouveau = malloc(sizeof(struct node)); + (*nouveau).l=mot; + for (int i=0; i<27; i++) nouveau->lettres[i]=NULL; *N = nouveau; } -void ajout_alphab(Node ** pn, char * mot) +void ajout_alphab(Node ** pn, char * mot,int cpt) { - if (*pn == NULL) - { - ajout_tete(pn,mot); - } - else - { - if (strcmp(mot, (*pn)->valeur) != 0) - { - ajout_alphab(pn[((*pn)->dernier)+1],mot); - (*pn)->dernier ++; - } + int i = 0; + while (mot[cpt] != '\0'){ + while ((*pn)->lettres[i] != NULL){ + if (strcmp(&(*pn)->l,mot) != 0){ + i++; + } + *pn=(*pn)->lettres[i]; + return ajout_alphab(pn,mot,cpt++); } + ajout(&(*pn)->lettres[i],mot[cpt]); + *pn=(*pn)->lettres[i]; + cpt++; + } } -Node * charger_arbre(){ - File * dico; +Node * charger_arbre(Node ** Arbre){ + FILE * dico; char mot[MAX_LETTRES]; - *dico = fopen("words.txt",'r'); + dico = fopen("words.txt","r"); while (fscanf(dico,"%s",mot) == 1){ - ajout_alphab(Arbre,mot); + ajout_alphab(Arbre,mot,0); } - fclose(); - return Arbre; + fclose(dico); + return *Arbre; } + +int main(){ + return 0; +} -- libgit2 0.21.2