Commit 2f31764524a9a1473972a62acd83fc8c9ede8347
1 parent
fde8b39d
end
Showing
1 changed file
with
71 additions
and
35 deletions
Show diff stats
@@ -4,22 +4,30 @@ | @@ -4,22 +4,30 @@ | ||
4 | #include <string.h> | 4 | #include <string.h> |
5 | #include "arbre.h" | 5 | #include "arbre.h" |
6 | 6 | ||
7 | -int main (int argc,char *argv[]){ | 7 | +void clearInputBuffer() // works only if the input buffer is not empty |
8 | +{ | ||
9 | + int c; | ||
10 | + do | ||
11 | + { | ||
12 | + c = getchar(); | ||
13 | + } while (c != '\n' && c != EOF); | ||
14 | +} | ||
15 | + | ||
16 | +void pause() | ||
17 | +{ | ||
18 | + printf("\nAppuyez sur ENTREE pour continuer...\n"); | ||
19 | + getchar(); | ||
20 | +} | ||
21 | +void bonjour(){ | ||
8 | system("clear"); | 22 | system("clear"); |
9 | printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); | 23 | printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); |
10 | printf("\nBonjour et bienvenue dans le projet de Programmation Avancée IMA 3\n\n"); | 24 | printf("\nBonjour et bienvenue dans le projet de Programmation Avancée IMA 3\n\n"); |
11 | printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"); | 25 | printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"); |
12 | - | ||
13 | - printf("\nAppuyez sur ENTREE pour continuer...\n"); | ||
14 | - getchar(); | ||
15 | - | ||
16 | - FILE* dico = NULL; | ||
17 | - char mot_dico[20]; //opti | ||
18 | - char mot_fichier[20]; | ||
19 | - | ||
20 | - | ||
21 | - if(argc <2){ | ||
22 | - | 26 | +} |
27 | + | ||
28 | + | ||
29 | +void test_arguments(int argc, char *argv[],char mot_dico[20], char mot_fichier[20]){ | ||
30 | + if(argc <2){ | ||
23 | printf("Vous n'avez pas entrée de dictionnaire ainsi que de fichier\n"); | 31 | printf("Vous n'avez pas entrée de dictionnaire ainsi que de fichier\n"); |
24 | printf("Veuillez entrez votre nom de dictionnaire\n"); | 32 | printf("Veuillez entrez votre nom de dictionnaire\n"); |
25 | scanf("%s",mot_dico); | 33 | scanf("%s",mot_dico); |
@@ -34,7 +42,9 @@ int main (int argc,char *argv[]){ | @@ -34,7 +42,9 @@ int main (int argc,char *argv[]){ | ||
34 | scanf("%s",mot_fichier); | 42 | scanf("%s",mot_fichier); |
35 | printf("\n\n"); | 43 | printf("\n\n"); |
36 | } | 44 | } |
37 | - | 45 | +} |
46 | + | ||
47 | +void lire_dico(int argc, char *argv[],char mot_dico[20], char mot_fichier[20],Dico* mondico,FILE* dico){ | ||
38 | printf("==================================================================\n"); | 48 | printf("==================================================================\n"); |
39 | if(argc >1){ | 49 | if(argc >1){ |
40 | printf("chargement de votre dictionnaire \n"); | 50 | printf("chargement de votre dictionnaire \n"); |
@@ -55,40 +65,38 @@ int main (int argc,char *argv[]){ | @@ -55,40 +65,38 @@ int main (int argc,char *argv[]){ | ||
55 | } | 65 | } |
56 | 66 | ||
57 | 67 | ||
58 | - struct dico *mondico=malloc(sizeof(struct dico)); | 68 | + |
59 | charger_dico(dico,&mondico); | 69 | charger_dico(dico,&mondico); |
60 | // affiche_dico(mondico); | 70 | // affiche_dico(mondico); |
61 | fclose(dico); | 71 | fclose(dico); |
62 | printf("==================================================================\n\n\n"); | 72 | printf("==================================================================\n\n\n"); |
63 | - | ||
64 | - printf("\nAppuyez sur ENTREE pour continuer...\n"); | ||
65 | - getchar(); | ||
66 | - getchar(); | 73 | +} |
67 | 74 | ||
68 | - | ||
69 | -// printf("1: %s:%d \n",mot,mot_existe(mondico->alpha[calculcase(mot[0])],mot,0)); | ||
70 | -// printf("2: %s:%d \n",mot2,mot_existe(mondico->alpha[calculcase(mot2[0])],mot2,0)); | ||
71 | - | ||
72 | - FILE* fichier_utilisateur = NULL; | 75 | +void lire_fichier(int argc, char *argv[],char mot_fichier[20],Dico* mondico,FILE** fichier_utilisateur){ |
73 | printf("##################################################################\n"); | 76 | printf("##################################################################\n"); |
74 | if(argc >2){ | 77 | if(argc >2){ |
75 | printf("Ouverture de votre fichier: %s \n",argv[2]); | 78 | printf("Ouverture de votre fichier: %s \n",argv[2]); |
76 | - fichier_utilisateur=fopen(argv[2],"r"); | ||
77 | - printf("Fermeture de votre fichier \n"); | 79 | + *fichier_utilisateur=fopen(argv[2],"r"); |
78 | } | 80 | } |
79 | else { | 81 | else { |
80 | printf("Ouverture de votre fichier: %s \n",mot_fichier); | 82 | printf("Ouverture de votre fichier: %s \n",mot_fichier); |
81 | - fichier_utilisateur=fopen(mot_fichier,"r"); | ||
82 | - printf("Fermeture de votre fichier \n"); | 83 | + *fichier_utilisateur=fopen(mot_fichier,"r"); |
84 | + | ||
83 | } | 85 | } |
84 | if (fichier_utilisateur==NULL){ | 86 | if (fichier_utilisateur==NULL){ |
85 | printf("Nous avons pas reussi à ouvrir le fichier\n"); | 87 | printf("Nous avons pas reussi à ouvrir le fichier\n"); |
86 | } | 88 | } |
87 | printf("##################################################################\n"); | 89 | printf("##################################################################\n"); |
88 | - printf("\nAppuyez sur ENTREE pour continuer...\n"); | ||
89 | - getchar(); | ||
90 | 90 | ||
91 | - if (fichier_utilisateur!=NULL){ | 91 | +} |
92 | + | ||
93 | +void fin(Dico* mondico){ | ||
94 | + printf("\n\n\nLe programme est fini, vous pouvez relancer une execution\nCommande: ./executable NOM-DICO NOM-FICHIER\n\nA bientôt\n"); | ||
95 | + free_dico(mondico); | ||
96 | +} | ||
97 | + | ||
98 | +void test_fichier(Dico* mondico,FILE* fichier_utilisateur){ | ||
99 | + if (fichier_utilisateur!=NULL){ | ||
92 | printf("\n\n¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤\n"); | 100 | printf("\n\n¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤\n"); |
93 | printf("analyse en cours\n\n"); | 101 | printf("analyse en cours\n\n"); |
94 | int juste=0; | 102 | int juste=0; |
@@ -96,15 +104,43 @@ int main (int argc,char *argv[]){ | @@ -96,15 +104,43 @@ int main (int argc,char *argv[]){ | ||
96 | analyse_fichier(fichier_utilisateur,mondico,&juste,&faux); | 104 | analyse_fichier(fichier_utilisateur,mondico,&juste,&faux); |
97 | printf("Votre fichier contient %d de mots, dont %d justes et %d faux.\n",juste+faux,juste,faux); | 105 | printf("Votre fichier contient %d de mots, dont %d justes et %d faux.\n",juste+faux,juste,faux); |
98 | printf("¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤\n"); | 106 | printf("¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤\n"); |
99 | - printf("\nAppuyez sur ENTREE pour continuer...\n"); | ||
100 | - getchar(); | 107 | + pause(); |
101 | } | 108 | } |
109 | +} | ||
110 | + | ||
111 | + | ||
112 | + | ||
113 | + | ||
114 | +int main (int argc,char *argv[]){ | ||
115 | + FILE* dico = NULL; | ||
116 | + char mot_dico[20]; //opti | ||
117 | + char mot_fichier[20]; | ||
118 | + FILE* fichier_utilisateur = NULL; | ||
119 | + struct dico mondico; | ||
120 | + | ||
121 | + | ||
122 | + bonjour(); | ||
123 | + | ||
124 | + pause(); | ||
125 | + | ||
126 | + test_arguments(argc,argv,mot_dico,mot_fichier); | ||
127 | + | ||
128 | + lire_dico(argc,argv,mot_dico,mot_fichier,&mondico,dico); | ||
129 | + | ||
130 | + clearInputBuffer(); | ||
131 | + pause(); | ||
132 | + | ||
133 | + lire_fichier(argc,argv,mot_fichier,&mondico,&fichier_utilisateur); | ||
134 | + | ||
135 | + | ||
136 | + pause(); | ||
137 | + | ||
138 | + test_fichier(&mondico,fichier_utilisateur); | ||
139 | + | ||
102 | 140 | ||
103 | - printf("\n\n\nLe programme est fini, vous pouvez relancer une execution\nCommande: ./executable NOM-DICO NOM-FICHIER\n\nA bientôt\n"); | ||
104 | - free_dico(mondico); | ||
105 | if (fichier_utilisateur!=NULL){ | 141 | if (fichier_utilisateur!=NULL){ |
106 | fclose(fichier_utilisateur); | 142 | fclose(fichier_utilisateur); |
107 | } | 143 | } |
108 | - | 144 | + fin(&mondico); |
109 | return 0; | 145 | return 0; |
110 | } | 146 | } |