diff --git a/main.c b/main.c index f32e3ca..03b9752 100644 --- a/main.c +++ b/main.c @@ -4,22 +4,30 @@ #include #include "arbre.h" -int main (int argc,char *argv[]){ +void clearInputBuffer() // works only if the input buffer is not empty +{ + int c; + do + { + c = getchar(); + } while (c != '\n' && c != EOF); +} + +void pause() +{ + printf("\nAppuyez sur ENTREE pour continuer...\n"); + getchar(); +} +void bonjour(){ system("clear"); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf("\nBonjour et bienvenue dans le projet de Programmation Avancée IMA 3\n\n"); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"); - - printf("\nAppuyez sur ENTREE pour continuer...\n"); - getchar(); - - FILE* dico = NULL; - char mot_dico[20]; //opti - char mot_fichier[20]; - - - if(argc <2){ - +} + + +void test_arguments(int argc, char *argv[],char mot_dico[20], char mot_fichier[20]){ + if(argc <2){ printf("Vous n'avez pas entrée de dictionnaire ainsi que de fichier\n"); printf("Veuillez entrez votre nom de dictionnaire\n"); scanf("%s",mot_dico); @@ -34,7 +42,9 @@ int main (int argc,char *argv[]){ scanf("%s",mot_fichier); printf("\n\n"); } - +} + +void lire_dico(int argc, char *argv[],char mot_dico[20], char mot_fichier[20],Dico* mondico,FILE* dico){ printf("==================================================================\n"); if(argc >1){ printf("chargement de votre dictionnaire \n"); @@ -55,40 +65,38 @@ int main (int argc,char *argv[]){ } - struct dico *mondico=malloc(sizeof(struct dico)); + charger_dico(dico,&mondico); // affiche_dico(mondico); fclose(dico); printf("==================================================================\n\n\n"); - - printf("\nAppuyez sur ENTREE pour continuer...\n"); - getchar(); - getchar(); +} - -// 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; +void lire_fichier(int argc, char *argv[],char mot_fichier[20],Dico* mondico,FILE** fichier_utilisateur){ printf("##################################################################\n"); if(argc >2){ printf("Ouverture de votre fichier: %s \n",argv[2]); - fichier_utilisateur=fopen(argv[2],"r"); - printf("Fermeture de votre fichier \n"); + *fichier_utilisateur=fopen(argv[2],"r"); } else { printf("Ouverture de votre fichier: %s \n",mot_fichier); - fichier_utilisateur=fopen(mot_fichier,"r"); - printf("Fermeture de votre fichier \n"); + *fichier_utilisateur=fopen(mot_fichier,"r"); + } if (fichier_utilisateur==NULL){ printf("Nous avons pas reussi à ouvrir le fichier\n"); } printf("##################################################################\n"); - printf("\nAppuyez sur ENTREE pour continuer...\n"); - getchar(); - if (fichier_utilisateur!=NULL){ +} + +void fin(Dico* mondico){ + printf("\n\n\nLe programme est fini, vous pouvez relancer une execution\nCommande: ./executable NOM-DICO NOM-FICHIER\n\nA bientôt\n"); + free_dico(mondico); +} + +void test_fichier(Dico* mondico,FILE* fichier_utilisateur){ + if (fichier_utilisateur!=NULL){ printf("\n\n¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤\n"); printf("analyse en cours\n\n"); int juste=0; @@ -96,15 +104,43 @@ int main (int argc,char *argv[]){ analyse_fichier(fichier_utilisateur,mondico,&juste,&faux); printf("Votre fichier contient %d de mots, dont %d justes et %d faux.\n",juste+faux,juste,faux); printf("¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤\n"); - printf("\nAppuyez sur ENTREE pour continuer...\n"); - getchar(); + pause(); } +} + + + + +int main (int argc,char *argv[]){ + FILE* dico = NULL; + char mot_dico[20]; //opti + char mot_fichier[20]; + FILE* fichier_utilisateur = NULL; + struct dico mondico; + + + bonjour(); + + pause(); + + test_arguments(argc,argv,mot_dico,mot_fichier); + + lire_dico(argc,argv,mot_dico,mot_fichier,&mondico,dico); + + clearInputBuffer(); + pause(); + + lire_fichier(argc,argv,mot_fichier,&mondico,&fichier_utilisateur); + + + pause(); + + test_fichier(&mondico,fichier_utilisateur); + - printf("\n\n\nLe programme est fini, vous pouvez relancer une execution\nCommande: ./executable NOM-DICO NOM-FICHIER\n\nA bientôt\n"); - free_dico(mondico); if (fichier_utilisateur!=NULL){ fclose(fichier_utilisateur); } - + fin(&mondico); return 0; } -- libgit2 0.21.2