a89bb625
bjeanlou
Update 8 withHash
|
1
2
3
4
5
|
#include "dico.h"
|
ccb47d03
bjeanlou
menu quit ok
|
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
FILE* getFile(string mode){
if(strcmp(mode,"r"))//mode!"=r", gestion de l'affichage suivant si mode= "r" ou "w"
printf("Tapez un nom du fichier avec son extension pour diriger la sortie des tests vers ce fichier.\n");
else printf("Tapez \"terminal\" pour entrer des mots depuis le terminal.\nTapez le nom du fichier avec son extension pour charger des mots depuis ce fichier\n");
FILE*file=NULL;
char fileName[30]={0};
//get the fileName
scanf("%30s",fileName);
if(!strcmp(fileName,"terminal")){
if(!strcmp(mode,"r"))
file=stdin;}
else file=fopen(fileName,mode);
//while there is a problem about it
while(file==NULL){
printf("desole, impossible d'ouvrir ce fichier.\nVeuillez essayer un autre fichier");
scanf("%30s",fileName);
if(!strcmp(fileName,"terminal")){
if(!strcmp(mode,"r"))
file=stdin;}
else file=fopen(fileName,mode);
|
a89bb625
bjeanlou
Update 8 withHash
|
30
|
}
|
a89bb625
bjeanlou
Update 8 withHash
|
31
|
|
ccb47d03
bjeanlou
menu quit ok
|
32
33
34
35
36
|
return file;
}
|
fb520d8f
bjeanlou
v1 ended
|
37
|
int main(void){
|
ccb47d03
bjeanlou
menu quit ok
|
38
|
int choice=0;
|
fb520d8f
bjeanlou
v1 ended
|
39
40
41
42
|
printf("Bienvenue dans le dictonnaire !\n\n");
dico monDico;
make_empty_dico(monDico);
|
ccb47d03
bjeanlou
menu quit ok
|
43
44
45
|
//initialisation
printf("Pour commencer, veuillez charger un dictionnaire.\n");
FILE*fileIn=getFile("r"),*fileOut=stdout;
|
b2638a8a
bjeanlou
création rapport
|
46
47
|
if(fileIn==stdin)
printf("Entrez vos mots (ctrl-D pour terminer le chargement):\n");
|
2c6f0266
bjeanlou
load and print OK
|
48
|
loadfrom_file(monDico,fileIn);
|
fb520d8f
bjeanlou
v1 ended
|
49
50
51
|
if(fileIn!=stdin)
fclose(fileIn);
|
2c6f0266
bjeanlou
load and print OK
|
52
|
|
fb520d8f
bjeanlou
v1 ended
|
53
|
|
ccb47d03
bjeanlou
menu quit ok
|
54
55
|
//boucle
while(1){
|
fb520d8f
bjeanlou
v1 ended
|
56
|
|
ccb47d03
bjeanlou
menu quit ok
|
57
58
59
60
|
clear();
//menu
printf("La sortie est branchee sur %s.\n",fileOut==stdout?"le terminal":"un fichier");
printf("Que voulez-vous faire ?\n");
|
fb520d8f
bjeanlou
v1 ended
|
61
|
|
ccb47d03
bjeanlou
menu quit ok
|
62
63
|
//end programme
printf("0) Fermer le programme.\n\n");
|
fb520d8f
bjeanlou
v1 ended
|
64
|
|
ccb47d03
bjeanlou
menu quit ok
|
65
66
67
68
69
|
//just about the dictionnary
printf("1) Lire le dictionnaire.\n");
printf("2) Rajouter des mots au dictionnaire\n");
printf("3) Effacer le dictionnaire\n");
printf("4) Remplacer le dictionnaire actuel par un autre dictionnaire\n\n");
|
fb520d8f
bjeanlou
v1 ended
|
70
|
|
ccb47d03
bjeanlou
menu quit ok
|
71
72
|
//word correction
printf("5) Tester si un mot, un ensemble de mot, une phrase ou un paragraphe appartient au dictionnaire.\n\n");
|
fb520d8f
bjeanlou
v1 ended
|
73
|
|
ccb47d03
bjeanlou
menu quit ok
|
74
75
76
|
//out stream
printf("6) Définir un fichier de sortie.\n");
printf("7) Définir la sortie sur le terminal.\n");
|
b2638a8a
bjeanlou
création rapport
|
77
|
|
fb520d8f
bjeanlou
v1 ended
|
78
79
80
|
|
b2638a8a
bjeanlou
création rapport
|
81
|
//saisie du choix
|
fb520d8f
bjeanlou
v1 ended
|
82
83
84
85
86
|
choice=getchar();
choice=ctoi(choice);
|
ccb47d03
bjeanlou
menu quit ok
|
87
88
|
switch(choice){
|
fb520d8f
bjeanlou
v1 ended
|
89
|
|
ccb47d03
bjeanlou
menu quit ok
|
90
91
92
|
case 0: {//sortie du programme
if(fileOut!=stdout)
fclose(fileOut);
|
fb520d8f
bjeanlou
v1 ended
|
93
94
95
96
97
98
99
|
fileOut=stdout;
delete_dico(monDico);
printf("Le dictionnaire vous dit aurevoir.\n\n\n");
return EXIT_SUCCESS;
}
|
ccb47d03
bjeanlou
menu quit ok
|
100
101
102
103
|
case 1: {//Lire le dictionnaire
printto_file(monDico,fileOut);
printf("dictionnaire imprimme\n");
break;}
|
fb520d8f
bjeanlou
v1 ended
|
104
|
|
ccb47d03
bjeanlou
menu quit ok
|
105
106
107
108
|
//manip sur le dictionnaire
case 2: {//ajout
fileIn=getFile("r");
|
b2638a8a
bjeanlou
création rapport
|
109
110
|
if(fileIn==stdin)
printf("Entrez vos mots (ctrl-D pour terminer le chargement):\n");
|
ccb47d03
bjeanlou
menu quit ok
|
111
|
loadfrom_file(monDico,fileIn);
|
b2638a8a
bjeanlou
création rapport
|
112
113
|
if(fileIn!=stdin)
fclose(fileIn);
|
fb520d8f
bjeanlou
v1 ended
|
114
|
fileIn=stdin;
|
ccb47d03
bjeanlou
menu quit ok
|
115
116
117
118
119
120
121
|
break;}
case 3: {//effacer
delete_dico(monDico);
printf("Le dictionnaire est maintenant vide.\n");
break;}
case 4: {//remplacer
delete_dico(monDico);
|
fb520d8f
bjeanlou
v1 ended
|
122
|
printf("Le dictionnaire est maintenant vide.\n");
|
ccb47d03
bjeanlou
menu quit ok
|
123
124
|
fileIn=getFile("r");
loadfrom_file(monDico,fileIn);
|
b2638a8a
bjeanlou
création rapport
|
125
126
|
if(fileIn!=stdin)
fclose(fileIn);
|
fb520d8f
bjeanlou
v1 ended
|
127
|
fileIn=stdin;
|
ccb47d03
bjeanlou
menu quit ok
|
128
|
break;}
|
fb520d8f
bjeanlou
v1 ended
|
129
|
|
ccb47d03
bjeanlou
menu quit ok
|
130
131
132
133
|
case 5: {//faire des tests
fileIn=getFile("r");
|
b2638a8a
bjeanlou
création rapport
|
134
135
|
if(fileIn==stdin)
printf("Entrez vos mots (ctrl-D pour terminer les tests):\n");
|
ccb47d03
bjeanlou
menu quit ok
|
136
|
test_words(monDico,fileIn,fileOut);
|
b2638a8a
bjeanlou
création rapport
|
137
138
|
if(fileIn!=stdin)
fclose(fileIn);
|
fb520d8f
bjeanlou
v1 ended
|
139
|
fileIn=stdin;
|
ccb47d03
bjeanlou
menu quit ok
|
140
|
break;}
|
fb520d8f
bjeanlou
v1 ended
|
141
142
|
|
ccb47d03
bjeanlou
menu quit ok
|
143
144
145
146
147
|
//définir la sortie des tests et de "Lire" le dictionnaire
case 6: {
if(fileOut!=stdout)
fclose(fileOut);
|
fb520d8f
bjeanlou
v1 ended
|
148
|
fileOut=getFile("a");
|
ccb47d03
bjeanlou
menu quit ok
|
149
150
151
152
153
154
|
break;}
case 7: {
if(fileOut!=stdout)
fclose(fileOut);
fileOut=stdout;
break;}
|
fb520d8f
bjeanlou
v1 ended
|
155
156
157
|
|
ccb47d03
bjeanlou
menu quit ok
|
158
159
160
|
//si le choix n'est pas parmi les précédents
default: {break;}
}
|
fb520d8f
bjeanlou
v1 ended
|
161
162
163
164
|
//protection, si le scanf pour le choix a un problème
choice=-1;
|
ccb47d03
bjeanlou
menu quit ok
|
165
166
|
pause();
}//end of while
|
8c671959
bjeanlou
No more seg fault
|
167
|
}
|