diff --git a/arbre.c b/arbre.c index d0eaf96..e0d4222 100644 --- a/arbre.c +++ b/arbre.c @@ -1,15 +1,21 @@ -#include "arbre.h" +#include +#include +#include +#include +#define TAILLE 27 +//#include "arbre.h" -// typedef struct arbre{ -// char val; -// struct arbre *suite[TAILLE]; -// bool finmot; //1 si fin de mot -// }Arbre; -// -// typedef struct dico { -// Arbre *alpha[TAILLE]; -// }Dico; + +typedef struct arbre{ + char val; + struct arbre *suite[TAILLE]; + bool finmot; //1 si fin de mot +}Arbre; + +typedef struct dico { + Arbre *alpha[TAILLE]; +}Dico; @@ -31,9 +37,20 @@ bool est_vide(struct arbre *arbre) return arbre==NULL; } -bool fin_de_mot(struct arbre *arbre) -{ - return arbre->finmot; +bool mot_existe(struct arbre *monarbre,char *mot,int i){ + if (monarbre==NULL){ +// printf("false\n"); + return false; + } +// printf("%c \n",(monarbre->val)); + if (mot[i+1]=='\0'){ +// printf("finmot\n"); + return monarbre->finmot; + } + else { + i++; + mot_existe(monarbre->suite[calculcase(mot[i])],mot,i); + } } void ini_dico(struct dico *pt_dico) @@ -45,7 +62,7 @@ void ini_dico(struct dico *pt_dico) } void creation_arbre(Arbre **ppt_arbre,char c) { - printf("creation arbre\n"); +// printf("creation arbre\n"); Arbre *monarbre=malloc(sizeof(struct arbre)); monarbre->val=c; monarbre->finmot=false; @@ -59,15 +76,16 @@ void creation_arbre(Arbre **ppt_arbre,char c) void ajout_mot(struct arbre **arbrecourant,char *mot,int i) { - printf("%s:length:%zu \n",mot,strlen(mot)); +// printf("%s:length:%zu \n",mot,strlen(mot)); if(mot[i]!='\0'){ - printf("\nlettre:%c; i=%d\n",mot[i],i); +// printf("\nlettre:%c; i=%d\n",mot[i],i); if (*arbrecourant==NULL){ creation_arbre(arbrecourant,mot[i]); } i++; - if(mot[i]!='\0'){ + if(mot[i+1]=='\0'){ + printf("findemot\n"); (*arbrecourant)->finmot=true; } ajout_mot(&((*arbrecourant)->suite[calculcase(mot[i])]),mot,i); @@ -79,8 +97,8 @@ void charger_arbre(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]); +// printf("mot:%s\n\n\n",mot); +// printf("\nlettre:%c\n",mot[0]); ajout_mot(&((*ppt_dico)->alpha[calculcase(mot[0])]),mot,0); } return ; @@ -137,16 +155,21 @@ void affiche_dico(struct dico *dico) } -// int main (){ -// 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)); -// charger_arbre(fp,&mondico); -// affiche_dico(mondico); -// -// -// free_dico(mondico); -// fclose(fp); -// return 0; -// } +int main (){ + 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)); + charger_arbre(fp,&mondico); + affiche_dico(mondico); + char mot[]="zombie"; + char mot2[]="zombbbiiee"; +// mot_existe(mondico->alpha[calculcase(mot[0])],mot,0); +// mot_existe(mondico->alpha[calculcase(mot2[0])],mot2,0); + + printf("1:%d \n",mot_existe(mondico->alpha[calculcase(mot[0])],mot,0)); + printf("3:%d \n",mot_existe(mondico->alpha[calculcase(mot2[0])],mot2,0)); + free_dico(mondico); + fclose(fp); + return 0; + } -- libgit2 0.21.2