Commit 12c9a42f249c7bc0875be88cf9c156eec29e2630
1 parent
54951130
Modification du fichier tree.c : prise en compte des mots avec endWord (booléen …
…spécifiant dans le dictionnaire si le mot est fini ou no) ; adaptation du code aux mots suivis de caractères spéciaux ; non prise en compte des potentiels chiffres collés aux mots.
Showing
2 changed files
with
24 additions
and
18 deletions
Show diff stats
doc.txt
... | ... | @@ -63,7 +63,8 @@ void add_in_tree(Node Tree, char word[]) |
63 | 63 | new->next[i]=NULL; |
64 | 64 | } |
65 | 65 | Tree2->next[letter-'a'] = new; |
66 | - Tree2->endWord = false; | |
66 | + if(!(Tree2->endWord)) | |
67 | + Tree2->endWord = false; | |
67 | 68 | Tree2=Tree2->next[letter-'a']; |
68 | 69 | printf("%c %d\t", letter, letter-'a'); |
69 | 70 | printf("okB %d\n", j); |
... | ... | @@ -77,12 +78,8 @@ void add_in_tree(Node Tree, char word[]) |
77 | 78 | |
78 | 79 | bool is_end_caract(char letter) |
79 | 80 | { |
80 | - int endCaract[nb_car] = {0, 44, 45, 46, 47}; // a remplir | |
81 | - for(int i=0; i<nb_car; i++) | |
82 | - { | |
83 | - if(letter==endCaract[i]) | |
84 | - return true; | |
85 | - } | |
81 | + if(letter==0) return true; | |
82 | + if((letter>=32 && letter<=47)||(letter>=58 && letter<=64)||(letter>=123 && letter<=126)||(letter==128)) return true; | |
86 | 83 | return false; |
87 | 84 | } |
88 | 85 | |
... | ... | @@ -94,26 +91,39 @@ char max_index(char word[]) |
94 | 91 | return index; |
95 | 92 | } |
96 | 93 | |
97 | -void scan_word(Node Tree, char word[], int* error) // ne gère pas les mots avec endWord = true | |
94 | +void scan_word(Node Tree, char word[], int* error) // si un mot démarre juste après un caractère de fin, la fonction ne lit pas les mots séparément | |
98 | 95 | { |
96 | + bool endWord; | |
97 | + bool stop = false; | |
99 | 98 | int ind = 0; |
100 | 99 | char letter; |
101 | 100 | Node Tree2 = Tree; |
102 | 101 | while(!is_end_caract(word[ind])) |
103 | 102 | { |
103 | + stop = false; | |
104 | 104 | letter = word[ind]; |
105 | 105 | if(Tree2->next[letter-'a']!=NULL) |
106 | 106 | { |
107 | 107 | ind++; |
108 | 108 | Tree2 = Tree2->next[letter-'a']; |
109 | + endWord = Tree2->endWord; | |
110 | + if(endWord) printf("end :: %s ::\n", word); | |
109 | 111 | } |
110 | 112 | else |
111 | 113 | { |
112 | 114 | printf("mot : %s erreur :%c %d \n", word, word[ind], word[ind]); |
113 | 115 | (*error)++; |
116 | + printf("%d\n", ind); | |
114 | 117 | ind = max_index(word); |
118 | + printf("%d\n", ind); | |
119 | + stop = true; | |
115 | 120 | } |
116 | 121 | } |
122 | + if(!endWord && !stop) | |
123 | + { | |
124 | + (*error)++; | |
125 | + printf("---%s---\n", word); | |
126 | + } | |
117 | 127 | } |
118 | 128 | |
119 | 129 | void read_txt(FILE* fp, Node* Tree, int* error) |
... | ... | @@ -180,10 +190,11 @@ void print_first(Node Tree) |
180 | 190 | { |
181 | 191 | Node cpTree = Tree; |
182 | 192 | int index = 0; |
183 | - while(!is_leaf(cpTree)) | |
193 | + while(!is_leaf(cpTree) || !(cpTree->endWord)) | |
184 | 194 | { |
185 | 195 | index = find_index(cpTree); |
186 | 196 | printf("%c\n", (cpTree->next[index])->letter); |
197 | + if(cpTree->next[index]->endWord) printf("fin\n"); | |
187 | 198 | cpTree=cpTree->next[index]; |
188 | 199 | } |
189 | 200 | } |
... | ... | @@ -201,18 +212,13 @@ int main(int argc, char *argv[]) |
201 | 212 | read_lib(fp_lib, &tree); |
202 | 213 | read_txt(fp_txt, &tree, &error); |
203 | 214 | |
204 | - printf("%p\n", tree); | |
215 | + // printf("%p\n", tree); | |
205 | 216 | |
206 | 217 | print_first(tree); |
207 | - printf("\n"); | |
208 | - print_tree(tree, 0); | |
218 | + //printf("\n"); | |
219 | + //print_tree(tree, 0); | |
209 | 220 | |
210 | 221 | printf("erreurs : %d\n", error); |
211 | 222 | |
212 | - int endCaract[nb_car] = {0, 44, 45, 46, 47}; // a remplir | |
213 | - for(int i=0; i<nb_car; i++) | |
214 | - { | |
215 | - printf("%c", endCaract[i]); | |
216 | - } | |
217 | 223 | return 0; |
218 | 224 | } | ... | ... |