#include #include #include typedef struct arbre{ char val; struct arbre *suite[26]; bool finmot; //1 si fin de mot }Arbre; typedef struct dico { Arbre *alpha[26]; }Dico; void arbre_vide(struct arbre ** pt_arbre) { *pt_arbre = NULL; } bool est_vide(struct arbre *arbre) { return arbre==NULL; } bool fin_de_mot(struct arbre *arbre) { return arbre->finmot; } void cons_dico(struct dico **pt_dico,char val){ Dico *mondico=malloc(sizeof(struct dico)); mondico->alpha[val-97]->val=val; // (ascii)->a = 97 for(int i=0;i<26;i++){ mondico->alpha[val-97]->suite[i]=NULL; } mondico->alpha[val-97]->finmot=false; (*pt_dico)=mondico; } void cons_arbre(struct arbre **pt_arbre,char val){ struct arbre *monarbre=malloc(sizeof(struct arbre)); monarbre->val=val; // (ascii)->a = 97 for(int i=0;i<26;i++){ monarbre->suite[i]=NULL; } monarbre->finmot=false; (*pt_arbre)=monarbre; } void ini_dico(struct dico * pt_dico){ for(int i=0;i<26;i++){ cons_dico(&pt_dico,97+i); } } void ajout_mot(struct dico *pt_dico,char mot[]){ int i=0; while(mot[i]!='\0'){ if (pt_dico->alpha[mot[i]-'a']==NULL){ cons_arbre(&(pt_dico->alpha[mot[i]-'a']),mot[i]); } i++; } pt_dico->alpha[mot[i]-'a']->finmot=true; } void charger_arbre(FILE *fp, struct dico **pt_dico) { char mot[20]; while (fscanf(fp, "%s", mot)!=EOF){ ajout_mot(*pt_dico,mot); } return ; } void free_arbre(struct dico **pt_dico){ if (*pt_dico-> } void affiche_dico(struct dico *dico){ if(dico==NULL){ return ; } for(int i=0;i<26;i++){ affiche_arbre(dico->alpha[i]); } } void affiche_arbre(struct arbre *arbre){ if(arbre==NULL){ return ; } printf("%c\n",arbre->val); for(int i=0;i<26;i++){ affiche_arbre(arbre->suite[i]); } } int main (){ Dico *mondico=malloc(sizeof(struct dico)); charger_arbre("dicotest.txt",mondico); return 0; }