main.c
4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "arbre.h"
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");
}
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);
printf("\n\n");
printf("Veuillez entrez votre nom de fichier\n");
scanf("%s",mot_fichier);
printf("\n\n");
}
else if(argc <3){
printf("Vous n'avez pas entrée de fichier\n");
printf("Veuillez entrez votre nom de fichier\n");
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");
printf("nom: %s\n",argv[1]);
dico=fopen(argv[1],"r");
}
else {
printf("chargement de votre dictionnaire \n");
printf("nom: %s\n",mot_dico);
dico=fopen(mot_dico,"r");
}
// else dico=fopen("words-no-accents","r");
if(dico == NULL){
printf("Nous avons pas compris votre demande.\nNous vous chargeons le dictionnaire par default\n");
printf("nom du dico: words-no-accents\n");
dico=fopen("words-no-accents","r");
}
charger_dico(dico,&mondico);
// affiche_dico(mondico);
fclose(dico);
printf("==================================================================\n\n\n");
}
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");
}
else {
printf("Ouverture de votre fichier: %s \n",mot_fichier);
*fichier_utilisateur=fopen(mot_fichier,"r");
}
if (fichier_utilisateur==NULL){
printf("Nous avons pas reussi à ouvrir le fichier\n");
}
printf("##################################################################\n");
}
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;
int faux=0;
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");
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);
if (fichier_utilisateur!=NULL){
fclose(fichier_utilisateur);
}
fin(&mondico);
return 0;
}