Commit 6aacc52e0ca2f2443275cf1eeb815e2afdbe8423
1 parent
30391ee4
Correction légère
Showing
7 changed files
with
180 additions
and
2 deletions
Show diff stats
doc.txt
main
No preview for this file type
... | ... | @@ -0,0 +1,34 @@ |
1 | +// -------------------------------------------------------- | |
2 | +// Projet IMA3 2019 - Lecture d'une bibliothèque | |
3 | +// Décompte du nombre de fautes d'orthographe dans un texte | |
4 | +// Normand Quentin & Rouillé Guillaume | |
5 | +// -------------------------------------------------------- | |
6 | + | |
7 | +#include "tree.h" | |
8 | + | |
9 | +int main(int argc, char *argv[]) | |
10 | +{ | |
11 | + Node tree = NULL; | |
12 | + int error = 0; | |
13 | + FILE* fp_lib; | |
14 | + FILE* fp_txt; | |
15 | + fp_lib = fopen(argv[argc-2], "r"); | |
16 | + fp_txt = fopen(argv[argc-1], "r"); | |
17 | + | |
18 | + init_tree(&tree); | |
19 | + read_lib(fp_lib, &tree); | |
20 | + read_txt(fp_txt, &tree, &error); | |
21 | + | |
22 | + // printf("%p\n", tree); | |
23 | + | |
24 | + //print_first(tree); | |
25 | + //printf("\n"); | |
26 | + //print_tree(tree, 0); | |
27 | + | |
28 | + printf("erreurs : %d\n", error); | |
29 | + | |
30 | + free_tree(&tree); | |
31 | + free(fp_lib); | |
32 | + free(fp_txt); | |
33 | + return EXIT_SUCCESS; | |
34 | +} | |
0 | 35 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,8 @@ |
1 | +In the old days, ants and cicadas were friends. They were very different. The ants were hardwood, but the cicadas were lazy. | |
2 | +In the summer, the ant families were very busy. They knew that in the winter they would have to stay in their anthill. They wanted to have enough food for the whole winter. | |
3 | +While the ants worked hard, the cicadas didn't do anything. They sang and danced all day. When they were hungry, they could fly to the farm and get something to eat. | |
4 | +One day the cicadas were singing and dancing. They saw a long line of ants bringing food to their anthill. The cicadas said, Stop, my silly friends. It's a very nice day. Come and dance with us. The ants said, Don't you know about winter? If you don't work now, you'll have trouble later. | |
5 | +But the cicadas said, We have strong wings. We can fly anywhere we want. Stupid ants! And they continued to sing and dance. | |
6 | +In the winter, it rained or snowed all the time, and it was very cold. In the anthill, there was singing and dancing. But the cicadas had nothing to eat. They asked the ants for some food. The ants said, We thought you could fly anywhere. Now who is stupid and silly? | |
7 | +The cicadas cried and said that their wings were wet from the rain. The ants said, We're sorry, but now it's to late. If we help you, there won't be enough food for us. Sorry, very sorry. And the ants closed their door. | |
8 | +The next day, when the ants opened their door, all the cicadas were dead! That's why we can hear cicadas sing in the summer, but in the winter they are silent.nt...... | |
0 | 9 | \ No newline at end of file | ... | ... |
texte.txt
... | ... | @@ -17,3 +17,10 @@ The ant and the cicada |
17 | 17 | The cicadas cried and said that their wings were wet from the rain. The ants said, We're sorry, but now it's to late. If we help you, there won't be enough food for us. Sorry, very sorry. And the ants closed their door. |
18 | 18 | |
19 | 19 | The next day, when the ants opened their door, all the cicadas were dead! That's why we can hear cicadas sing in the summer, but in the winter they are silent. |
20 | + | |
21 | + | |
22 | + | |
23 | + | |
24 | + | |
25 | + | |
26 | + | ... | ... |
... | ... | @@ -0,0 +1,61 @@ |
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | +#include <stdbool.h> | |
4 | + | |
5 | +typedef struct node* Node; | |
6 | + | |
7 | +typedef struct node { | |
8 | + char letter; | |
9 | + Node next[26]; | |
10 | + bool endWord; | |
11 | +}node; | |
12 | + | |
13 | +void mk_empty_tree(Node* Tree) | |
14 | +{ | |
15 | + *Tree = NULL; | |
16 | +} | |
17 | + | |
18 | +bool is_empty_tree(Node* Tree) | |
19 | +{ | |
20 | + return(*Tree==NULL); | |
21 | +} | |
22 | + | |
23 | +void init_tree(Node* Tree) | |
24 | +{ | |
25 | + if(is_empty_tree(Tree)) | |
26 | + { | |
27 | + *Tree = malloc(sizeof(Node)); | |
28 | + Tree->letter = '?'; | |
29 | + Tree->endWord = false; | |
30 | + for(int i=0; i<26; i++) | |
31 | + Tree->next[i] = NULL; | |
32 | + } | |
33 | +} | |
34 | + | |
35 | +void add_in_tree(Node Tree, char word[]) | |
36 | +{ | |
37 | + char letter = word[0]; | |
38 | + while(letter != '/0') | |
39 | + { | |
40 | + if(Tree->next[letter-'a']!=NULL) | |
41 | + Tree = Tree->next[letter-'a']; | |
42 | + else | |
43 | + { | |
44 | + Node new = NULL; | |
45 | + new = malloc(sizeof(Node)); | |
46 | + new->letter = letter; | |
47 | + for(int i=0; i<26; i++) | |
48 | + { | |
49 | + new->next[i]=NULL; | |
50 | + } | |
51 | + Tree->next[letter-'a'] = new; | |
52 | + } | |
53 | + } | |
54 | + | |
55 | +} | |
56 | + | |
57 | + | |
58 | +int main(int argc, char argv[]) | |
59 | +{ | |
60 | + return 0; | |
61 | +} | ... | ... |
... | ... | @@ -0,0 +1,68 @@ |
1 | +// -------------------------------------------------------- | |
2 | +// Projet IMA3 2019 - Lecture d'une bibliothèque | |
3 | +// Décompte du nombre de fautes d'orthographe dans un texte | |
4 | +// Normand Quentin & Rouillé Guillaume | |
5 | +// -------------------------------------------------------- | |
6 | + | |
7 | +// Initialisation des variables et inclusion des bibliothèques | |
8 | +#include <stdio.h> | |
9 | +#include <stdlib.h> | |
10 | +#include <stdbool.h> | |
11 | +#define MAX 30 // taille maximale d'une chaîne lue dans un fichier | |
12 | +#define NB_CARAC 27 // nombre de caractères différents pouvant être identifiés -> 89 avec accentués | |
13 | + | |
14 | +// Déclaration de la structure 'trie' ou 'arbre indexé', ainsi que des pointeurs associés | |
15 | +typedef struct node* Node; | |
16 | + | |
17 | +typedef struct node { | |
18 | + char letter; | |
19 | + Node next[NB_CARAC]; | |
20 | + bool endWord; | |
21 | +}node; | |
22 | + | |
23 | +// Fonction permettant de savoir si la structure est vide | |
24 | +bool is_empty_tree(Node Tree); | |
25 | + | |
26 | +// Fonction permettant de savoir si le tableau 'next' est un tableau de pointeurs NULL | |
27 | +bool is_leaf(Node Tree); | |
28 | + | |
29 | +// Initialisation de la structure accueillant le dictionnaire | |
30 | +void init_tree(Node* Tree); | |
31 | + | |
32 | +// Détermine l'indice de rangement dans le tableau 'next' du caractère 'letter' | |
33 | +int find_caract_indice(char letter); // Ne fonctionne pas pour les caractères accentués | |
34 | + | |
35 | + | |
36 | +// Fonction d'ajout d'un mot 'word' dans la structure 'tree' de type 'arbre indexé' | |
37 | +void add_in_tree(Node Tree, char word[]); | |
38 | + | |
39 | +// Fonction qui détermine si le caractère est un caractère de fin de mot (espace, ',', ';', '.', etc..) | |
40 | +bool is_end_caract(char letter); | |
41 | + | |
42 | +// Renvoi l'indice maximum du mot 'word' | |
43 | +char max_index(char word[]); | |
44 | + | |
45 | +// Détermine si le mot 'word' est présent dans l'arbre indexé | |
46 | +void scan_word(Node Tree, char word[], int* error); | |
47 | + | |
48 | +// Retourne 'true' si le mot 'word' est non accentué, 'false' sinon | |
49 | +bool no_accent(char word[]); | |
50 | + | |
51 | +// Transmet les mots du texte à analyser à 'scan_word' | |
52 | +void read_txt(FILE* fp, Node* Tree, int* error); | |
53 | + | |
54 | +// Transmet les mots de la biliothèque à 'add_in_tree' | |
55 | +void read_lib(FILE* fp, Node* Tree); | |
56 | + | |
57 | +// A SUPPRIMER | |
58 | +void print_tree(Node Tree, int index); | |
59 | + | |
60 | +// A SUPPRIMER | |
61 | +int find_index(Node tree); | |
62 | + | |
63 | +// A SUPPRIMER | |
64 | +void print_first(Node Tree); | |
65 | + | |
66 | +// Libère l'espace mémoire associé à l'arbre indexé | |
67 | +void free_tree(Node* Tree); | |
68 | + | ... | ... |