00160129
rsSimonin
creation main.c
|
1
2
3
4
5
6
|
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "arbre.h"
|
2f317645
rsSimonin
end
|
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
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(){
|
35bdc271
rsimonin
affichage
|
22
|
system("clear");
|
1e85143f
rsimonin
modif_affichage
|
23
24
25
|
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("\nBonjour et bienvenue dans le projet de Programmation Avancée IMA 3\n\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
|
2f317645
rsSimonin
end
|
26
27
28
29
30
|
}
void test_arguments(int argc, char *argv[],char mot_dico[20], char mot_fichier[20]){
if(argc <2){
|
1e85143f
rsimonin
modif_affichage
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
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");
}
|
2f317645
rsSimonin
end
|
45
46
47
|
}
void lire_dico(int argc, char *argv[],char mot_dico[20], char mot_fichier[20],Dico* mondico,FILE* dico){
|
1e85143f
rsimonin
modif_affichage
|
48
|
printf("==================================================================\n");
|
35bdc271
rsimonin
affichage
|
49
50
51
52
53
|
if(argc >1){
printf("chargement de votre dictionnaire \n");
printf("nom: %s\n",argv[1]);
dico=fopen(argv[1],"r");
}
|
1e85143f
rsimonin
modif_affichage
|
54
55
56
57
58
|
else {
printf("chargement de votre dictionnaire \n");
printf("nom: %s\n",mot_dico);
dico=fopen(mot_dico,"r");
}
|
35bdc271
rsimonin
affichage
|
59
60
61
|
// else dico=fopen("words-no-accents","r");
if(dico == NULL){
|
1e85143f
rsimonin
modif_affichage
|
62
|
printf("Nous avons pas compris votre demande.\nNous vous chargeons le dictionnaire par default\n");
|
35bdc271
rsimonin
affichage
|
63
64
|
printf("nom du dico: words-no-accents\n");
dico=fopen("words-no-accents","r");
|
1e85143f
rsimonin
modif_affichage
|
65
66
|
}
|
35bdc271
rsimonin
affichage
|
67
|
|
2f317645
rsSimonin
end
|
68
|
|
35bdc271
rsimonin
affichage
|
69
70
71
|
charger_dico(dico,&mondico);
// affiche_dico(mondico);
fclose(dico);
|
1e85143f
rsimonin
modif_affichage
|
72
|
printf("==================================================================\n\n\n");
|
2f317645
rsSimonin
end
|
73
|
}
|
1e85143f
rsimonin
modif_affichage
|
74
|
|
2f317645
rsSimonin
end
|
75
|
void lire_fichier(int argc, char *argv[],char mot_fichier[20],Dico* mondico,FILE** fichier_utilisateur){
|
1e85143f
rsimonin
modif_affichage
|
76
|
printf("##################################################################\n");
|
35bdc271
rsimonin
affichage
|
77
|
if(argc >2){
|
1e85143f
rsimonin
modif_affichage
|
78
|
printf("Ouverture de votre fichier: %s \n",argv[2]);
|
2f317645
rsSimonin
end
|
79
|
*fichier_utilisateur=fopen(argv[2],"r");
|
1e85143f
rsimonin
modif_affichage
|
80
81
82
|
}
else {
printf("Ouverture de votre fichier: %s \n",mot_fichier);
|
2f317645
rsSimonin
end
|
83
84
|
*fichier_utilisateur=fopen(mot_fichier,"r");
|
1e85143f
rsimonin
modif_affichage
|
85
86
87
|
}
if (fichier_utilisateur==NULL){
printf("Nous avons pas reussi à ouvrir le fichier\n");
|
35bdc271
rsimonin
affichage
|
88
|
}
|
1e85143f
rsimonin
modif_affichage
|
89
|
printf("##################################################################\n");
|
35bdc271
rsimonin
affichage
|
90
|
|
2f317645
rsSimonin
end
|
91
92
93
94
95
96
97
98
99
|
}
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){
|
1e85143f
rsimonin
modif_affichage
|
100
101
|
printf("\n\n¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤\n");
printf("analyse en cours\n\n");
|
35bdc271
rsimonin
affichage
|
102
103
104
|
int juste=0;
int faux=0;
analyse_fichier(fichier_utilisateur,mondico,&juste,&faux);
|
1e85143f
rsimonin
modif_affichage
|
105
106
|
printf("Votre fichier contient %d de mots, dont %d justes et %d faux.\n",juste+faux,juste,faux);
printf("¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤\n");
|
2f317645
rsSimonin
end
|
107
|
pause();
|
35bdc271
rsimonin
affichage
|
108
|
}
|
2f317645
rsSimonin
end
|
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
|
}
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);
|
35bdc271
rsimonin
affichage
|
140
|
|
35bdc271
rsimonin
affichage
|
141
142
143
|
if (fichier_utilisateur!=NULL){
fclose(fichier_utilisateur);
}
|
2f317645
rsSimonin
end
|
144
|
fin(&mondico);
|
00160129
rsSimonin
creation main.c
|
145
146
|
return 0;
}
|