#include #include #include #include #include "arbre.h" int calculcase(char c) { if(c==39){ return 26; } else if(c<97){ return c-'A'; } else { return c-'a'; } } bool mot_existe(struct arbre *monarbre,char *mot,int i){ if (monarbre==NULL){ //printf("%s n'est pas dans le dictionnaire\n",mot); return false; } if (mot[i+1]=='\0'){ //printf("%s %d\n",mot, monarbre->finmot); return monarbre->finmot; } i++; return mot_existe(monarbre->suite[calculcase(mot[i])],mot,i); } void ini_dico(struct dico *pt_dico) { //printf("Initialisation du dictionnaire\n"); 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) { // printf("%s:length:%zu \n",mot,strlen(mot)); if(mot[i]!='\0'){ // printf("\nlettre:%c; i=%d\n",mot[i],i); if (*arbrecourant==NULL){ creation_arbre(arbrecourant,mot[i]); } if(mot[i+1]=='\0'){ //printf("mot:%s %c\n",mot,mot[i]); (*arbrecourant)->finmot=true; } i++; ajout_mot(&((*arbrecourant)->suite[calculcase(mot[i])]),mot,i); } else return ; } void charger_dico(FILE *fp, struct dico **ppt_dico) { char mot[20]; ini_dico(*ppt_dico); while (fscanf(fp, "%s", mot)==1){ // printf("mot:%s\n\n\n",mot); // printf("\nlettre:%c\n",mot[0]); ajout_mot(&((*ppt_dico)->alpha[calculcase(mot[0])]),mot,0); } return ; } void free_arbre(struct arbre *pt_arbre) { if (pt_arbre==NULL){ return ; } for(int i=0;isuite[i])); } free(pt_arbre); } void free_dico(struct dico *pt_dico) { if (pt_dico==NULL){ return ; } for(int i=0;ialpha[i])); } //free(pt_dico); } void affiche_arbre(struct arbre *arbre) { if(arbre==NULL){ return ; } printf("%c:",arbre->val); for(int i=0;isuite[i]); } } void affiche_dico(struct dico *dico) { if(dico==NULL){ return ; } printf("---------------------------------------\n"); for(int i=0;ialpha[i]); printf("\n"); } } void analyse_fichier(FILE *fp,Dico *pt_dico, int *nb_t, int *nb_f){ int nbmot_t=0; int nbmot_f=0; char mot[20]; while (fscanf(fp, "%s", mot)==1){ // printf("mot:%s\n\n\n",mot); // printf("\nlettre:%c\n",mot[0]); if(mot_existe(pt_dico->alpha[calculcase(mot[0])],mot,0)==1){ nbmot_t++; } else nbmot_f++; } *nb_t=nbmot_t; *nb_f=nbmot_f; }