Commit 46b621e77c209d02076d81cca05a8c9d3257e1c3

Authored by rsimonin
1 parent 1a9a077f

chargementdu deuxieme fichier et fonction d'analyse

Showing 1 changed file with 61 additions and 11 deletions   Show diff stats
... ... @@ -49,7 +49,8 @@ bool mot_existe(struct arbre *monarbre,char *mot,int i){
49 49 }
50 50 else {
51 51 i++;
52   - mot_existe(monarbre->suite[calculcase(mot[i])],mot,i);
  52 + return mot_existe(monarbre->suite[calculcase(mot[i])],mot,i);
  53 +
53 54 }
54 55 }
55 56  
... ... @@ -85,15 +86,15 @@ void ajout_mot(struct arbre **arbrecourant,char *mot,int i)
85 86 }
86 87 i++;
87 88 if(mot[i+1]=='\0'){
88   - printf("findemot\n");
  89 +// printf("mot:%s %d\n\n\n",mot,i);
89 90 (*arbrecourant)->finmot=true;
90 91 }
91   - ajout_mot(&((*arbrecourant)->suite[calculcase(mot[i])]),mot,i);
  92 + else ajout_mot(&((*arbrecourant)->suite[calculcase(mot[i])]),mot,i);
92 93 }
93 94  
94 95 }
95 96  
96   -void charger_arbre(FILE *fp, struct dico **ppt_dico)
  97 +void charger_dico(FILE *fp, struct dico **ppt_dico)
97 98 { char mot[20];
98 99 ini_dico(*ppt_dico);
99 100 while (fscanf(fp, "%s", mot)==1){
... ... @@ -155,21 +156,70 @@ void affiche_dico(struct dico *dico)
155 156 }
156 157  
157 158  
158   -int main (){
159   - FILE* fp = fopen("words-no-accents","r"); //amelioration entrée
160   - if(fp == NULL){ return EXIT_FAILURE;} //File is not readable
  159 +void analyse_fichier(FILE *fp,Dico *pt_dico, int *res[2]){
  160 + int nbmot_t=0;
  161 + int nbmot_f=0;
  162 + char mot[20];
  163 + while (fscanf(fp, "%s", mot)==1){
  164 +// printf("mot:%s\n\n\n",mot);
  165 +// printf("\nlettre:%c\n",mot[0]);
  166 + if(mot_existe(pt_dico->alpha[calculcase(mot[0])],mot,0)){
  167 + nbmot_t++;
  168 + }
  169 + else nbmot_f++;
  170 + }
  171 + *res[0]=nbmot_t;
  172 + *res[1]=nbmot_f;
  173 +}
  174 +
  175 +int main (int argc,char *argv[]){
  176 + FILE* dico = NULL;
  177 + if(argc >1){
  178 + printf("chargement de votre dictionnaire \n");
  179 + dico=fopen(argv[1],"r");
  180 + }
  181 +// else dico=fopen("words-no-accents","r");
  182 +
  183 + if(dico == NULL){
  184 +// return EXIT_FAILURE;
  185 + printf("chargement du dictionnaire par default");
  186 + dico=fopen("words-no-accents","r");
  187 + } //File is not readable
161 188  
162 189 struct dico *mondico=malloc(sizeof(struct dico));
163   - charger_arbre(fp,&mondico);
  190 + charger_dico(dico,&mondico);
164 191 affiche_dico(mondico);
  192 + fclose(dico);
165 193 char mot[]="zombie";
166 194 char mot2[]="zombbbiiee";
167 195 // mot_existe(mondico->alpha[calculcase(mot[0])],mot,0);
168 196 // mot_existe(mondico->alpha[calculcase(mot2[0])],mot2,0);
169 197  
170   - printf("1:%d \n",mot_existe(mondico->alpha[calculcase(mot[0])],mot,0));
171   - printf("3:%d \n",mot_existe(mondico->alpha[calculcase(mot2[0])],mot2,0));
  198 + printf("%s:%d \n",mot,mot_existe(mondico->alpha[calculcase(mot[0])],mot,0));
  199 + printf("%s:%d \n",mot2,mot_existe(mondico->alpha[calculcase(mot2[0])],mot2,0));
  200 +
  201 + FILE* fichier_utilisateur = NULL;
  202 + if(argc >2){
  203 + printf("Analyse de votre fichier \n");
  204 + fichier_utilisateur=fopen(argv[2],"r");
  205 + printf("Fin Analyse de votre fichier \n");
  206 + }
  207 +
  208 +// if (fichier_utilisateur!=NULL){
  209 +// printf("analyse en cours");
  210 +// int *res[2];
  211 +// analyse_fichier(fichier_utilisateur,mondico,res);
  212 +// printf("juste:%d \n",*res[0]);
  213 +// printf("faux:%d \n",*res[1]);
  214 +// }
  215 +
  216 + printf("fin programme \n");
  217 +
  218 +
172 219 free_dico(mondico);
173   - fclose(fp);
  220 + if (fichier_utilisateur!=NULL){
  221 + fclose(fichier_utilisateur);
  222 + }
  223 +
174 224 return 0;
175 225 }
... ...