Commit 6d4badb45fa738e1804eb977801945efc5d78db1
1 parent
352cf5c6
Suppression fichiers inutiles
Showing
1 changed file
with
0 additions
and
369 deletions
Show diff stats
projetfinalwchar_t2.c deleted
@@ -1,369 +0,0 @@ | @@ -1,369 +0,0 @@ | ||
1 | -#include <stdio.h> | ||
2 | -#include <stdlib.h> | ||
3 | -#include <stddef.h> | ||
4 | -#include <locale.h> | ||
5 | - | ||
6 | -#define A 26 | ||
7 | -#define B 137 | ||
8 | - | ||
9 | -struct node { | ||
10 | - wchar_t lettre; | ||
11 | - struct cell* listeFils; | ||
12 | -}; | ||
13 | - | ||
14 | -struct cell { | ||
15 | - struct node* arbre; | ||
16 | - struct cell* arbreSuivant; | ||
17 | -}; | ||
18 | - | ||
19 | -void lien_listeFils(struct cell** pL) { | ||
20 | - struct cell* p; | ||
21 | - p = malloc(sizeof(struct cell)); | ||
22 | - | ||
23 | - (*pL)->arbre->listeFils = p; | ||
24 | -} | ||
25 | - | ||
26 | -void initialisation_tab_arbre(struct node tab[]) { | ||
27 | - for(int i = 0; i < A; i++) { | ||
28 | - tab[i].lettre = 97+i; //ajout lettres minuscules | ||
29 | - tab[i].listeFils = NULL; | ||
30 | - } | ||
31 | - tab[A].lettre = 39; | ||
32 | - tab[A].listeFils = NULL; | ||
33 | - for(int i = 0; i < B-(A+1); i++) { | ||
34 | - tab[(A+1)+i].lettre = 128+i; //ajout carractère spéciaux | ||
35 | - tab[(A+1)+i].listeFils = NULL; | ||
36 | - } | ||
37 | - | ||
38 | -} | ||
39 | - | ||
40 | -void ajout_tete(wchar_t elem, struct cell** pL) { | ||
41 | - struct cell* p; | ||
42 | - p = malloc(sizeof(struct cell)); | ||
43 | - p->arbre = malloc(sizeof(struct node)); | ||
44 | - p->arbre->listeFils = NULL; | ||
45 | - p->arbre->lettre = elem; | ||
46 | - p->arbreSuivant = *pL; | ||
47 | - *pL = p; | ||
48 | -} | ||
49 | - | ||
50 | -struct cell ** insertion(wchar_t elem, struct cell** pL) { | ||
51 | - if(((*pL) == NULL) || ((*pL)->arbre->lettre > elem)) { | ||
52 | - ajout_tete(elem, pL); | ||
53 | - return &(*pL)->arbre->listeFils; | ||
54 | - } | ||
55 | - else if((*pL)->arbre->lettre == elem) { | ||
56 | - return &(*pL)->arbre->listeFils; | ||
57 | - } | ||
58 | - else { | ||
59 | - return insertion(elem, &(*pL)->arbreSuivant); | ||
60 | - } | ||
61 | -} | ||
62 | - | ||
63 | -wchar_t conversion_accent(wchar_t lettre) { // Conversion Unicode -> ASCII 256 | ||
64 | - switch(lettre) { | ||
65 | - case 192 : //À | ||
66 | - lettre = 182; | ||
67 | - break; | ||
68 | - case 193 : //Á | ||
69 | - lettre = 181; | ||
70 | - break; | ||
71 | - case 194 : //Â | ||
72 | - lettre = 182; | ||
73 | - break; | ||
74 | - case 198 : //Æ | ||
75 | - lettre = 146; | ||
76 | - break; | ||
77 | - case 199 : //Ç | ||
78 | - lettre = 128; | ||
79 | - break; | ||
80 | - case 200 : //È | ||
81 | - lettre = 212; | ||
82 | - break; | ||
83 | - case 201 : //É | ||
84 | - lettre = 144; | ||
85 | - break; | ||
86 | - case 202 : //Ê | ||
87 | - lettre = 210; | ||
88 | - break; | ||
89 | - case 203 : //Ë | ||
90 | - lettre = 211; | ||
91 | - break; | ||
92 | - case 204 : //Ì | ||
93 | - lettre = 141; | ||
94 | - break; | ||
95 | - case 205 : //Í | ||
96 | - lettre = 214; | ||
97 | - break; | ||
98 | - case 206 : //Î | ||
99 | - lettre = 215; | ||
100 | - break; | ||
101 | - case 207 : //Ï | ||
102 | - lettre = 216; | ||
103 | - break; | ||
104 | - case 209 : //Ñ | ||
105 | - lettre = 165; | ||
106 | - break; | ||
107 | - case 210 : //Ò | ||
108 | - lettre = 227; | ||
109 | - break; | ||
110 | - case 211 : //Ó | ||
111 | - lettre = 224; | ||
112 | - break; | ||
113 | - case 212 : //Ô | ||
114 | - lettre = 226; | ||
115 | - break; | ||
116 | - /* case 140 : //Œ | ||
117 | - lettre = | ||
118 | - break;*/ | ||
119 | - case 217 : //Ù | ||
120 | - lettre = 235; | ||
121 | - break; | ||
122 | - case 218 : //Ú | ||
123 | - lettre = 233; | ||
124 | - break; | ||
125 | - case 219 : //Û | ||
126 | - lettre = 234; | ||
127 | - break; | ||
128 | - case 220 : //Ü | ||
129 | - lettre = 154; | ||
130 | - break; | ||
131 | - case 221 : //Ý | ||
132 | - lettre = 237; | ||
133 | - break; | ||
134 | - /*case 159 : //Ÿ | ||
135 | - lettre = | ||
136 | - break;*/ | ||
137 | - case 224 : //à | ||
138 | - lettre = 233; | ||
139 | - break; | ||
140 | - case 225 : //á | ||
141 | - lettre = 160; | ||
142 | - break; | ||
143 | - case 226 : //â | ||
144 | - lettre = 131; | ||
145 | - break; | ||
146 | - case 230 : //æ | ||
147 | - lettre = 145; | ||
148 | - break; | ||
149 | - case 231 : //ç | ||
150 | - lettre = 135; | ||
151 | - break; | ||
152 | - case 232 : //è | ||
153 | - lettre = 138; | ||
154 | - break; | ||
155 | - case 233 : //é | ||
156 | - lettre = 130; | ||
157 | - break; | ||
158 | - case 234 : //ê | ||
159 | - lettre = 136; | ||
160 | - break; | ||
161 | - case 235 : //ë | ||
162 | - lettre = 137; | ||
163 | - break; | ||
164 | - case 236 : //ì | ||
165 | - lettre = 141; | ||
166 | - break; | ||
167 | - case 237 : //í | ||
168 | - lettre = 161; | ||
169 | - break; | ||
170 | - case 238 : //î | ||
171 | - lettre = 140; | ||
172 | - break; | ||
173 | - case 239 : //ï | ||
174 | - lettre = 139; | ||
175 | - break; | ||
176 | - case 241 : //ñ | ||
177 | - lettre = 164; | ||
178 | - break; | ||
179 | - case 242 : //ò | ||
180 | - lettre = 149; | ||
181 | - break; | ||
182 | - case 243 : //ó | ||
183 | - lettre = 162; | ||
184 | - break; | ||
185 | - case 244 : //ô | ||
186 | - lettre = 147; | ||
187 | - break; | ||
188 | - /*case 156 : //œ | ||
189 | - lettre = | ||
190 | - break;*/ | ||
191 | - case 249 : //ù | ||
192 | - lettre = 151; | ||
193 | - break; | ||
194 | - case 250 : //ú | ||
195 | - lettre = 163; | ||
196 | - break; | ||
197 | - case 251 : //û | ||
198 | - lettre = 150; | ||
199 | - break; | ||
200 | - /*case 252 : //ü | ||
201 | - lettre = | ||
202 | - break;*/ | ||
203 | - case 253 : //ý | ||
204 | - lettre = 263; | ||
205 | - break; | ||
206 | - case 255 : //ÿ | ||
207 | - lettre = 152; | ||
208 | - break; | ||
209 | - default : | ||
210 | - break; | ||
211 | - } | ||
212 | - return lettre; | ||
213 | -} | ||
214 | - | ||
215 | -int indice_lettre(struct node tab_arbre_prcp[], wchar_t lettre) | ||
216 | -{ | ||
217 | - int i= A+1; | ||
218 | - while(i>A && i<B){ | ||
219 | - if(lettre == tab_arbre_prcp[i].lettre ){ | ||
220 | - return i; | ||
221 | - } | ||
222 | - i++; | ||
223 | - } | ||
224 | -return 0; | ||
225 | -} | ||
226 | - | ||
227 | -void remplir_dico(FILE* fd, struct node tab_arbre_prcp[]) { | ||
228 | - | ||
229 | - struct cell** localisationArbre = NULL; | ||
230 | - int cptmot = 0; | ||
231 | - wchar_t motLu[50]; | ||
232 | - while(fwscanf(fd, L"%ls", motLu)==1) { | ||
233 | - wprintf(L"mot lu : %ls\n", motLu); | ||
234 | - int wchar_tEstUneLettre = 1; | ||
235 | - int i = 0; | ||
236 | - cptmot += 1; | ||
237 | - if((motLu[0] >= 'A') && (motLu[0] <= 'Z')) { | ||
238 | - localisationArbre = &tab_arbre_prcp[motLu[0]-65].listeFils; | ||
239 | - } | ||
240 | - else if((motLu[0] >= 'a') && (motLu[0] <= 'z')) { | ||
241 | - localisationArbre = &tab_arbre_prcp[motLu[0]-97].listeFils; | ||
242 | - } | ||
243 | - else if((motLu[0] >= 128) && (motLu[0] <= 237)) { | ||
244 | - motLu[0] = conversion_accent(motLu[0]); | ||
245 | - wprintf(L" 1er lettre lue apres convversion : %ld\n", motLu[0]); | ||
246 | - localisationArbre = &tab_arbre_prcp[indice_lettre(tab_arbre_prcp, motLu[0])].listeFils; | ||
247 | - | ||
248 | - } | ||
249 | - else { | ||
250 | - wprintf(L"Erreur remplissage dico : L'un des caracteres n'est pas une lettre\n"); | ||
251 | - wprintf(L"Mot : %ls incorrect\n", motLu); | ||
252 | - wchar_tEstUneLettre = 0; | ||
253 | - } | ||
254 | - while((motLu[i] != '\0') && (wchar_tEstUneLettre == 1)) { | ||
255 | - i += 1; | ||
256 | - wprintf(L"lettre lue %ld\n", motLu[i]); | ||
257 | - if(motLu[i] > 127) { | ||
258 | - motLu[i] = conversion_accent(motLu[i]); | ||
259 | - wprintf(L"lettre lue apres convversion : %ld\n", motLu[i]); | ||
260 | - } | ||
261 | - localisationArbre = insertion(motLu[i], localisationArbre); | ||
262 | - } | ||
263 | - wprintf(L"mot lu 2: %ls\n", motLu); | ||
264 | - } | ||
265 | - wprintf(L"\n"); | ||
266 | - fclose(fd); | ||
267 | - wprintf(L"%d mots inseres dans le dictionnaire.\n", cptmot); | ||
268 | -} | ||
269 | - | ||
270 | -struct cell** test_mot(wchar_t mot, struct cell** localisation, int* verif) { | ||
271 | - | ||
272 | - if((*localisation == NULL) || (*localisation)->arbre->lettre > mot) { | ||
273 | - *verif = 0; | ||
274 | - return NULL; | ||
275 | - } | ||
276 | - if((*localisation)->arbre->lettre == mot) { | ||
277 | - return &(*localisation)->arbre->listeFils; | ||
278 | - } | ||
279 | - else { | ||
280 | - return test_mot(mot, &(*localisation)->arbreSuivant, verif); | ||
281 | - } | ||
282 | -} | ||
283 | - | ||
284 | -void correction_txt(FILE* fd, struct node tab_arbre_prcp[]) { | ||
285 | - struct cell** localisationArbre = NULL; | ||
286 | - int verif; | ||
287 | - wchar_t motLu[50]; | ||
288 | - while(fwscanf(fd, L"%ls", motLu)==1) { | ||
289 | - wprintf(L"mot lu : %ls\n", motLu); | ||
290 | - verif = 1; | ||
291 | - int i = 0; | ||
292 | - if((motLu[0] >= 'A') && (motLu[0] <= 'Z')) { | ||
293 | - localisationArbre = &tab_arbre_prcp[motLu[0]-65].listeFils; | ||
294 | - } | ||
295 | - else if((motLu[0] >= 'a') && (motLu[0] <= 'z')) { | ||
296 | - localisationArbre = &tab_arbre_prcp[motLu[0]-97].listeFils; | ||
297 | - } | ||
298 | - else { | ||
299 | - wprintf(L"Erreur correction txt : L'un des caracteres n'est pas une lettre\n"); | ||
300 | - verif = 0; | ||
301 | - } | ||
302 | - while((verif == 1) && (motLu[i] != '\0')) { | ||
303 | - i += 1; | ||
304 | - if(motLu[i] > 127) {motLu[i] = conversion_accent(motLu[i]); | ||
305 | - wprintf(L"mot lu 2 : %ls\n", motLu);} | ||
306 | - localisationArbre = test_mot(motLu[i], localisationArbre, &verif); | ||
307 | - wprintf(L"lettre lue %ld\n", motLu[i]); | ||
308 | - } | ||
309 | - wprintf(L"\n"); | ||
310 | - if(verif == 0) wprintf(L"Mot %ls non present dans le dicitonnaire.\n", motLu); | ||
311 | - | ||
312 | - } | ||
313 | - fclose(fd); | ||
314 | -} | ||
315 | - | ||
316 | -void correction_mot(struct node tab_arbre_prcp[]) { | ||
317 | - struct cell** localisationArbre = NULL; | ||
318 | - int verif; | ||
319 | - wchar_t motLu[50]; | ||
320 | - wprintf(L"Entrez un mot ou une phrase a corriger : \n(0 pour quitter)\n"); | ||
321 | - while(wscanf(L"%ls", motLu)==1) { | ||
322 | - if(motLu[0]=='0') return; | ||
323 | - verif = 1; | ||
324 | - int i = 0; | ||
325 | - if((motLu[0] >= 'A') && (motLu[0] <= 'Z')) { | ||
326 | - localisationArbre = &tab_arbre_prcp[motLu[0]-65].listeFils; | ||
327 | - } | ||
328 | - else if((motLu[0] >= 'a') && (motLu[0] <= 'z')) { | ||
329 | - localisationArbre = &tab_arbre_prcp[motLu[0]-97].listeFils; | ||
330 | - } | ||
331 | - else { | ||
332 | - wprintf(L"Erreur correction mot : L'un des caract%lcres n'est pas une lettre\n", 130); | ||
333 | - verif = 0; | ||
334 | - } | ||
335 | - while((verif == 1) && (motLu[i] != '\0')) { | ||
336 | - i += 1; | ||
337 | - wprintf(L"lettre lue %ld\n", motLu[i]); | ||
338 | - localisationArbre = test_mot(motLu[i], localisationArbre, &verif); | ||
339 | - } | ||
340 | - if(verif == 0) wprintf(L"Mot : %ls non present dans le dicitonnaire.\n", motLu); | ||
341 | - else wprintf(L"Mot : %ls correct\n", motLu); | ||
342 | - } | ||
343 | -} | ||
344 | - | ||
345 | - | ||
346 | -int main(int argc, char* argv[]) { | ||
347 | - FILE* dico = NULL; | ||
348 | - FILE* txt = NULL; | ||
349 | - struct node tab_arbre[B]; | ||
350 | - | ||
351 | - if(argc>2) { | ||
352 | - dico = fopen(argv[1], "r"); | ||
353 | - txt = fopen(argv[2], "r"); | ||
354 | - } | ||
355 | - else { | ||
356 | - dico = NULL; | ||
357 | - txt = NULL; | ||
358 | - } | ||
359 | - if ((dico == NULL) || (txt == NULL)) { | ||
360 | - wprintf(L"Erreur : il manque un ou plusieurs fichiers !\n"); | ||
361 | - return 1; | ||
362 | - } | ||
363 | - initialisation_tab_arbre(tab_arbre); | ||
364 | - remplir_dico(dico, tab_arbre); //on suppose qu'il n'y a pas d'accents dans le dictionnaire | ||
365 | - correction_txt(txt, tab_arbre); | ||
366 | - correction_mot(tab_arbre); | ||
367 | - | ||
368 | - return 0; | ||
369 | -} |