d75f444a
pvernier
ajout de la desal...
|
1
2
3
4
5
|
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <locale.h>
|
54b57c55
tvieuble
création du main ...
|
6
|
#include "fonctions.h"
|
d75f444a
pvernier
ajout de la desal...
|
7
|
|
54b57c55
tvieuble
création du main ...
|
8
|
#define A 256
|
d75f444a
pvernier
ajout de la desal...
|
9
|
|
d75f444a
pvernier
ajout de la desal...
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
void ajout_tete(wchar_t elem, struct cell** pL) {
struct cell* p;
p = malloc(sizeof(struct cell));
p->arbre = malloc(sizeof(struct node));
p->arbre->listeFils = NULL;
p->arbre->lettre = elem;
p->arbreSuivant = *pL;
*pL = p;
}
struct cell ** insertion(wchar_t elem, struct cell** pL) {
if(((*pL) == NULL) || ((*pL)->arbre->lettre > elem)) {
ajout_tete(elem, pL);
return &(*pL)->arbre->listeFils;
}
else if((*pL)->arbre->lettre == elem) {
return &(*pL)->arbre->listeFils;
}
else {
return insertion(elem, &(*pL)->arbreSuivant);
}
}
|
e2bf24c0
tvieuble
push
|
33
34
|
void initialisation_tab_arbre(struct node tab[]) {
int i = 0;
|
c21ed069
tvieuble
correction projet...
|
35
|
for(wchar_t u = 'a'; u < A; u++) {
|
e2bf24c0
tvieuble
push
|
36
37
38
39
|
tab[i].lettre = u; //ajout lettres minuscules
tab[i].listeFils = NULL;
i++;
}
|
c21ed069
tvieuble
correction projet...
|
40
41
|
tab[i].lettre = '?';
tab[i+1].lettre = '!';
|
4c1aa780
tvieuble
projetfinalaccent2.c
|
42
|
tab[i+2].lettre = '\'';
|
54b57c55
tvieuble
création du main ...
|
43
44
45
46
|
tab[i+3].lettre = '.'; //Ajout des caractères de ponctuation par défau
tab[i+4].lettre = ':';
tab[i+5].lettre = ';';
for(int j = 0; j <= 5; j++) {
|
c21ed069
tvieuble
correction projet...
|
47
48
|
tab[i+j].listeFils = NULL;
insertion('\0', &(tab[i+j].listeFils));
|
e2bf24c0
tvieuble
push
|
49
50
51
|
}
}
|
54b57c55
tvieuble
création du main ...
|
52
|
int indice_lettre(struct node tab_arbre_prcp[], wchar_t lettre) {
|
4c1aa780
tvieuble
projetfinalaccent2.c
|
53
54
|
int i = 0;
while(i >= 0 && i < A){
|
d75f444a
pvernier
ajout de la desal...
|
55
56
57
58
59
|
if(lettre == tab_arbre_prcp[i].lettre ){
return i;
}
i++;
}
|
4c1aa780
tvieuble
projetfinalaccent2.c
|
60
|
return -1;
|
d75f444a
pvernier
ajout de la desal...
|
61
62
63
64
65
66
67
68
|
}
void remplir_dico(FILE* fd, struct node tab_arbre_prcp[]) {
struct cell** localisationArbre = NULL;
int cptmot = 0, indice = 0;
wchar_t motLu[50];
while(fwscanf(fd, L"%ls", motLu)==1) {
|
d75f444a
pvernier
ajout de la desal...
|
69
70
71
72
73
74
75
76
77
|
int estUneLettre = 1;
int i = 0;
cptmot += 1;
if((motLu[0] >= 'A') && (motLu[0] <= 'Z')) {
localisationArbre = &tab_arbre_prcp[motLu[0]-65].listeFils;
}
else if((motLu[0] >= 'a') && (motLu[0] <= 'z')) {
localisationArbre = &tab_arbre_prcp[motLu[0]-97].listeFils;
}
|
ee3fc0eb
tvieuble
Ajout caractères ...
|
78
|
else if((motLu[0] < 'A') || (motLu[0] > 'z')) {
|
d75f444a
pvernier
ajout de la desal...
|
79
80
|
indice = indice_lettre(tab_arbre_prcp, motLu[0]);
localisationArbre = &tab_arbre_prcp[indice].listeFils;
|
4c1aa780
tvieuble
projetfinalaccent2.c
|
81
|
if(indice == -1) {
|
d75f444a
pvernier
ajout de la desal...
|
82
83
84
85
86
87
88
89
90
91
92
93
|
wprintf(L"Erreur remplissage dico : L'un des caracteres n'est pas une lettre\n");
wprintf(L"Mot : %ls incorrect\n", motLu);
estUneLettre = 0;
}
}
else {
wprintf(L"Erreur remplissage dico : L'un des caracteres n'est pas une lettre\n");
wprintf(L"Mot : %ls incorrect\n", motLu);
estUneLettre = 0;
}
while((motLu[i] != '\0') && (estUneLettre == 1)) {
i += 1;
|
d75f444a
pvernier
ajout de la desal...
|
94
95
96
97
98
99
100
101
|
localisationArbre = insertion(motLu[i], localisationArbre);
}
}
wprintf(L"\n");
fclose(fd);
wprintf(L"%d mots inseres dans le dictionnaire.\n", cptmot);
}
|
ee3fc0eb
tvieuble
Ajout caractères ...
|
102
|
struct cell ** test_mot(wchar_t mot, struct cell** localisation, int* verif) {
|
d75f444a
pvernier
ajout de la desal...
|
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
if((*localisation == NULL) || (*localisation)->arbre->lettre > mot) {
*verif = 0;
return NULL;
}
if((*localisation)->arbre->lettre == mot) {
return &(*localisation)->arbre->listeFils;
}
else {
return test_mot(mot, &(*localisation)->arbreSuivant, verif);
}
}
void correction_txt(FILE* fd, struct node tab_arbre_prcp[]) {
struct cell** localisationArbre = NULL;
int verif;
|
ee3fc0eb
tvieuble
Ajout caractères ...
|
119
|
int indice = 0, cptfaute = 0;
|
d75f444a
pvernier
ajout de la desal...
|
120
121
122
123
124
125
126
127
128
129
|
wchar_t motLu[50];
while(fwscanf(fd, L"%ls", motLu)==1) {
verif = 1;
int i = 0;
if((motLu[0] >= 'A') && (motLu[0] <= 'Z')) {
localisationArbre = &tab_arbre_prcp[motLu[0]-65].listeFils;
}
else if((motLu[0] >= 'a') && (motLu[0] <= 'z')) {
localisationArbre = &tab_arbre_prcp[motLu[0]-97].listeFils;
}
|
ee3fc0eb
tvieuble
Ajout caractères ...
|
130
|
else if((motLu[0] < 'A') || (motLu[0] > 'z')) {
|
d75f444a
pvernier
ajout de la desal...
|
131
132
|
indice = indice_lettre(tab_arbre_prcp, motLu[0]);
localisationArbre = &tab_arbre_prcp[indice].listeFils;
|
4c1aa780
tvieuble
projetfinalaccent2.c
|
133
|
if(indice == -1) {
|
ee3fc0eb
tvieuble
Ajout caractères ...
|
134
|
wprintf(L"Erreur correction txt : L'un des caracteres n'est pas une lettre\n");
|
d75f444a
pvernier
ajout de la desal...
|
135
136
137
138
139
140
141
142
143
|
verif = 0;
}
}
else {
wprintf(L"Erreur correction txt : L'un des caracteres n'est pas une lettre\n");
verif = 0;
}
while((verif == 1) && (motLu[i] != '\0')) {
i += 1;
|
ee3fc0eb
tvieuble
Ajout caractères ...
|
144
|
if((motLu[i] == '.') || (motLu[i] == ',') || (motLu[i] == ';') || (motLu[i] == ':') || (motLu[i] == '!') || (motLu[i] == '?')) motLu[i] = '\0'; //prendre en compte les fins de phrase
|
d75f444a
pvernier
ajout de la desal...
|
145
146
|
localisationArbre = test_mot(motLu[i], localisationArbre, &verif);
}
|
ee3fc0eb
tvieuble
Ajout caractères ...
|
147
148
149
150
|
if(verif == 0) {
wprintf(L"Mot %ls non present dans le dicitonnaire.\n", motLu);
cptfaute += 1;
}
|
d75f444a
pvernier
ajout de la desal...
|
151
|
}
|
60787f42
tvieuble
correction foncti...
|
152
|
wprintf(L"Le texte comporte %d faute(s)\n", cptfaute);
|
d75f444a
pvernier
ajout de la desal...
|
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
fclose(fd);
}
void correction_mot(struct node tab_arbre_prcp[]) {
struct cell** localisationArbre = NULL;
int verif;
int indice = 0;
wchar_t motLu[50];
wprintf(L"Entrez un mot ou une phrase a corriger : \n(0 pour quitter)\n");
while(wscanf(L"%ls", motLu)==1) {
if(motLu[0]=='0') return;
verif = 1;
int i = 0;
if((motLu[0] >= 'A') && (motLu[0] <= 'Z')) {
localisationArbre = &tab_arbre_prcp[motLu[0]-65].listeFils;
}
else if((motLu[0] >= 'a') && (motLu[0] <= 'z')) {
localisationArbre = &tab_arbre_prcp[motLu[0]-97].listeFils;
}
|
ee3fc0eb
tvieuble
Ajout caractères ...
|
172
|
else if((motLu[0] < 'A') || (motLu[0] > 'z')) {
|
d75f444a
pvernier
ajout de la desal...
|
173
174
|
indice = indice_lettre(tab_arbre_prcp, motLu[0]);
localisationArbre = &tab_arbre_prcp[indice].listeFils;
|
4c1aa780
tvieuble
projetfinalaccent2.c
|
175
|
if(indice == -1) {
|
e2bf24c0
tvieuble
push
|
176
|
wprintf(L"Erreur correction mot : L'un des caracteres n'est pas une lettre\n");
|
d75f444a
pvernier
ajout de la desal...
|
177
178
179
180
181
182
183
184
185
|
verif = 0;
}
}
else {
wprintf(L"Erreur correction mot : L'un des caracteres n'est pas une lettre\n");
verif = 0;
}
while((verif == 1) && (motLu[i] != '\0')) {
i += 1;
|
ee3fc0eb
tvieuble
Ajout caractères ...
|
186
|
if((motLu[i] == '.') || (motLu[i] == ',') || (motLu[i] == ';') || (motLu[i] == ':') || (motLu[i] == '!') || (motLu[i] == '?')) motLu[i] = '\0';
|
d75f444a
pvernier
ajout de la desal...
|
187
188
|
localisationArbre = test_mot(motLu[i], localisationArbre, &verif);
}
|
ee3fc0eb
tvieuble
Ajout caractères ...
|
189
190
191
|
if(verif == 0) {
wprintf(L"Mot : %ls non present dans le dicitonnaire.\n", motLu);
}
|
d75f444a
pvernier
ajout de la desal...
|
192
193
194
195
|
else wprintf(L"Mot : %ls correct\n", motLu);
}
}
|
d75f444a
pvernier
ajout de la desal...
|
196
197
|
void desalocationArbre(struct cell** pL) {
|
c21ed069
tvieuble
correction projet...
|
198
199
|
if ((*pL) == NULL) return;
|
d75f444a
pvernier
ajout de la desal...
|
200
201
|
desalocationArbre(&(*pL)-> arbreSuivant);
desalocationArbre(&(*pL)-> arbre -> listeFils);
|
d75f444a
pvernier
ajout de la desal...
|
202
203
204
205
|
free((*pL) -> arbre);
free(*pL);
}
|
54b57c55
tvieuble
création du main ...
|
206
|
void desalocationTableauArbre(struct node tab_arbre[]) {
|
d75f444a
pvernier
ajout de la desal...
|
207
|
int i = 0;
|
6e68d779
tvieuble
correction sur pr...
|
208
|
for(wchar_t u = 'a'; u <= A+5; u++) { //A+5 car ajout de 5 caractères de ponctuation en plus des lettres
|
ee3fc0eb
tvieuble
Ajout caractères ...
|
209
|
desalocationArbre(&tab_arbre[i].listeFils);
|
d75f444a
pvernier
ajout de la desal...
|
210
211
212
213
|
i++;
}
}
|