diff --git a/arbre.c b/arbre.c index caae66c..824cbc2 100644 --- a/arbre.c +++ b/arbre.c @@ -3,26 +3,30 @@ #include #include +#define TAILLE 27 typedef struct arbre{ char val; - struct arbre *suite[26]; + struct arbre *suite[TAILLE]; bool finmot; //1 si fin de mot }Arbre; typedef struct dico { - Arbre *alpha[26]; + Arbre *alpha[TAILLE]; }Dico; int calculcase(char c){ + if(c==39){ + return 26; + } + else if(c<97){ + return c-'A'; + } + else { return c-'a'; -} - -void arbre_vide(struct arbre ** pt_arbre) -{ - *pt_arbre = NULL; + } } bool est_vide(struct arbre *arbre) @@ -37,11 +41,21 @@ bool fin_de_mot(struct arbre *arbre) void ini_dico(struct dico * pt_dico){ printf("ini_dico\n"); - for(int i=0;i<26;i++){ + for(int i=0;ialpha[i]=NULL; } } - +void creation_arbre(Arbre **ppt_arbre,char c){ + printf("creation arbre\n"); + Arbre *monarbre=malloc(sizeof(struct arbre)); + monarbre->val=c; + monarbre->finmot=false; + for(int j=0;jsuite[j]=NULL; + } + *ppt_arbre=monarbre; +} + void ajout_mot(struct arbre **arbrecourant,char *mot,int i){ @@ -50,15 +64,7 @@ void ajout_mot(struct arbre **arbrecourant,char *mot,int i){ if(mot[i]!='\0'){ printf("\nlettre:%c; i=%d\n",mot[i],i); if (*arbrecourant==NULL){ - - printf("creation arbre\n"); - Arbre *monarbre=malloc(sizeof(struct arbre)); - monarbre->val=mot[i]; - monarbre->finmot=false; - for(int j=0;j<26;j++){ - monarbre->suite[j]=NULL; - } - *arbrecourant=monarbre; + creation_arbre(arbrecourant,mot[i]); } i++; ajout_mot(&((*arbrecourant)->suite[calculcase(mot[i])]),mot,i); @@ -82,7 +88,7 @@ void free_arbre(struct arbre *pt_arbre){ if (pt_arbre==NULL){ return ; } - for(int i=0;i<26;i++){ + for(int i=0;isuite[i])); } free(pt_arbre); @@ -93,7 +99,7 @@ void free_dico(struct dico *pt_dico){ return ; } - for(int i=0;i<26;i++){ + for(int i=0;ialpha[i])); } @@ -105,7 +111,7 @@ void affiche_arbre(struct arbre *arbre){ return ; } printf("%c:",arbre->val); - for(int i=0;i<26;i++){ + for(int i=0;isuite[i]); } } @@ -115,7 +121,7 @@ void affiche_dico(struct dico *dico){ return ; } printf("---------------------------------------\n"); - for(int i=0;i<26;i++){ + for(int i=0;ialpha[i]); printf("\n"); @@ -125,7 +131,7 @@ void affiche_dico(struct dico *dico){ int main (){ - FILE* fp = fopen("dicotest.txt","r"); //amelioration entrée + FILE* fp = fopen("words-no-accents","r"); //amelioration entrée if(fp == NULL){ return EXIT_FAILURE;} //File is not readable struct dico *mondico=malloc(sizeof(struct dico)); -- libgit2 0.21.2