From d6eeddaa3870a8d46b1a7af5e22ef204e2c5d8fd Mon Sep 17 00:00:00 2001 From: rsimonin Date: Thu, 11 Apr 2019 11:56:12 +0200 Subject: [PATCH] toutes les fonctions sont finis --- arbre.c | 63 +++++++++++++++++++++++++++------------------------------------ 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/arbre.c b/arbre.c index acbb321..ee8cb9e 100644 --- a/arbre.c +++ b/arbre.c @@ -31,27 +31,18 @@ int calculcase(char c) return c-'a'; } } - -bool est_vide(struct arbre *arbre) -{ - return arbre==NULL; -} - + bool mot_existe(struct arbre *monarbre,char *mot,int i){ if (monarbre==NULL){ -// printf("false\n"); + printf("%s n'est pas dans le dictionnaire\n",mot); return false; } -// printf("%c \n",(monarbre->val)); if (mot[i+1]=='\0'){ -// printf("finmot\n"); + printf("%s %d\n",mot, monarbre->finmot); return monarbre->finmot; } - else { - i++; - return mot_existe(monarbre->suite[calculcase(mot[i])],mot,i); - - } + i++; + return mot_existe(monarbre->suite[calculcase(mot[i])],mot,i); } void ini_dico(struct dico *pt_dico) @@ -84,13 +75,14 @@ void ajout_mot(struct arbre **arbrecourant,char *mot,int i) if (*arbrecourant==NULL){ creation_arbre(arbrecourant,mot[i]); } - i++; if(mot[i+1]=='\0'){ -// printf("mot:%s %d\n\n\n",mot,i); + printf("mot:%s %c\n",mot,mot[i]); (*arbrecourant)->finmot=true; } - else ajout_mot(&((*arbrecourant)->suite[calculcase(mot[i])]),mot,i); + i++; + ajout_mot(&((*arbrecourant)->suite[calculcase(mot[i])]),mot,i); } + else return ; } @@ -156,20 +148,20 @@ void affiche_dico(struct dico *dico) } -void analyse_fichier(FILE *fp,Dico *pt_dico, int *res[2]){ +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)){ + if(mot_existe(pt_dico->alpha[calculcase(mot[0])],mot,0)==1){ nbmot_t++; } else nbmot_f++; } - *res[0]=nbmot_t; - *res[1]=nbmot_f; + *nb_t=nbmot_t; + *nb_f=nbmot_f; } int main (int argc,char *argv[]){ @@ -188,15 +180,15 @@ int main (int argc,char *argv[]){ struct dico *mondico=malloc(sizeof(struct dico)); charger_dico(dico,&mondico); - affiche_dico(mondico); +// affiche_dico(mondico); fclose(dico); char mot[]="zombie"; - char mot2[]="zombbbiiee"; -// mot_existe(mondico->alpha[calculcase(mot[0])],mot,0); -// mot_existe(mondico->alpha[calculcase(mot2[0])],mot2,0); + char mot2[]="chaine"; +// mot_existe(mondico->alpha[calculcase('r')],"rerere",0); + //mot_existe(mondico->alpha[calculcase(mot2[0])],mot2,0); - printf("%s:%d \n",mot,mot_existe(mondico->alpha[calculcase(mot[0])],mot,0)); - printf("%s:%d \n",mot2,mot_existe(mondico->alpha[calculcase(mot2[0])],mot2,0)); + printf("1: %s:%d \n",mot,mot_existe(mondico->alpha[calculcase(mot[0])],mot,0)); + printf("2: %s:%d \n",mot2,mot_existe(mondico->alpha[calculcase(mot2[0])],mot2,0)); FILE* fichier_utilisateur = NULL; if(argc >2){ @@ -205,17 +197,16 @@ int main (int argc,char *argv[]){ printf("Fin Analyse de votre fichier \n"); } -// if (fichier_utilisateur!=NULL){ -// printf("analyse en cours"); -// int *res[2]; -// analyse_fichier(fichier_utilisateur,mondico,res); -// printf("juste:%d \n",*res[0]); -// printf("faux:%d \n",*res[1]); -// } + if (fichier_utilisateur!=NULL){ + printf("analyse en cours\n"); + int juste=0; + int faux=0; + analyse_fichier(fichier_utilisateur,mondico,&juste,&faux); + printf("juste:%d \n",juste); + printf("faux:%d \n",faux); + } printf("fin programme \n"); - - free_dico(mondico); if (fichier_utilisateur!=NULL){ fclose(fichier_utilisateur); -- libgit2 0.21.2