From 46b621e77c209d02076d81cca05a8c9d3257e1c3 Mon Sep 17 00:00:00 2001 From: rsimonin Date: Tue, 9 Apr 2019 14:48:39 +0200 Subject: [PATCH] chargementdu deuxieme fichier et fonction d'analyse --- arbre.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/arbre.c b/arbre.c index e0d4222..acbb321 100644 --- a/arbre.c +++ b/arbre.c @@ -49,7 +49,8 @@ bool mot_existe(struct arbre *monarbre,char *mot,int i){ } else { i++; - mot_existe(monarbre->suite[calculcase(mot[i])],mot,i); + return mot_existe(monarbre->suite[calculcase(mot[i])],mot,i); + } } @@ -85,15 +86,15 @@ void ajout_mot(struct arbre **arbrecourant,char *mot,int i) } i++; if(mot[i+1]=='\0'){ - printf("findemot\n"); +// printf("mot:%s %d\n\n\n",mot,i); (*arbrecourant)->finmot=true; } - ajout_mot(&((*arbrecourant)->suite[calculcase(mot[i])]),mot,i); + else ajout_mot(&((*arbrecourant)->suite[calculcase(mot[i])]),mot,i); } } -void charger_arbre(FILE *fp, struct dico **ppt_dico) +void charger_dico(FILE *fp, struct dico **ppt_dico) { char mot[20]; ini_dico(*ppt_dico); while (fscanf(fp, "%s", mot)==1){ @@ -155,21 +156,70 @@ 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 +void analyse_fichier(FILE *fp,Dico *pt_dico, int *res[2]){ + 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)){ + nbmot_t++; + } + else nbmot_f++; + } + *res[0]=nbmot_t; + *res[1]=nbmot_f; +} + +int main (int argc,char *argv[]){ + FILE* dico = NULL; + if(argc >1){ + printf("chargement de votre dictionnaire \n"); + dico=fopen(argv[1],"r"); + } +// else dico=fopen("words-no-accents","r"); + + if(dico == NULL){ +// return EXIT_FAILURE; + printf("chargement du dictionnaire par default"); + dico=fopen("words-no-accents","r"); + } //File is not readable struct dico *mondico=malloc(sizeof(struct dico)); - charger_arbre(fp,&mondico); + charger_dico(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); - 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)); + 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)); + + FILE* fichier_utilisateur = NULL; + if(argc >2){ + printf("Analyse de votre fichier \n"); + fichier_utilisateur=fopen(argv[2],"r"); + 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]); +// } + + printf("fin programme \n"); + + free_dico(mondico); - fclose(fp); + if (fichier_utilisateur!=NULL){ + fclose(fichier_utilisateur); + } + return 0; } -- libgit2 0.21.2