Commit 284154cafeed848e011db89d8aadae10eb748abe
1 parent
34d66d1d
gestion des accents
Showing
6 changed files
with
22 additions
and
17 deletions
Show diff stats
dico_test
@@ -2,8 +2,9 @@ | @@ -2,8 +2,9 @@ | ||
2 | 2 | ||
3 | int main() | 3 | int main() |
4 | { | 4 | { |
5 | - FILE* fp = fopen("american-english","r"); | ||
6 | - //FILE* fp = fopen("dico_test","r"); | 5 | + setlocale(LC_ALL, ""); |
6 | + //FILE* fp = fopen("american-english","r"); | ||
7 | + FILE* fp = fopen("dico_test","r"); | ||
7 | 8 | ||
8 | if(fp == NULL) return 1 ; //File is not readable | 9 | if(fp == NULL) return 1 ; //File is not readable |
9 | 10 | ||
@@ -18,11 +19,11 @@ int main() | @@ -18,11 +19,11 @@ int main() | ||
18 | 19 | ||
19 | printf("Loading done!\n"); | 20 | printf("Loading done!\n"); |
20 | 21 | ||
21 | - char mot[50]; | 22 | + wchar_t mot[50]; |
22 | int taille; | 23 | int taille; |
23 | taille = 8; | 24 | taille = 8; |
24 | - scanf("%s",mot); | ||
25 | - scanf("%d",&taille); | 25 | + wscanf(L"%ls",mot); |
26 | + wscanf(L"%d",&taille); | ||
26 | int result; | 27 | int result; |
27 | result = find_mot(tab,mot,taille,0); | 28 | result = find_mot(tab,mot,taille,0); |
28 | printf("%d\n",result); | 29 | printf("%d\n",result); |
1 | #include "tree.h" | 1 | #include "tree.h" |
2 | 2 | ||
3 | -void cons_tree(struct node ** ptr_tree, int val) | 3 | +void cons_tree(struct node ** ptr_tree, wchar_t val) |
4 | { | 4 | { |
5 | *ptr_tree = malloc(sizeof(struct node)); | 5 | *ptr_tree = malloc(sizeof(struct node)); |
6 | (*ptr_tree)->val = val; | 6 | (*ptr_tree)->val = val; |
@@ -20,7 +20,7 @@ int is_leaf(struct node *tree) | @@ -20,7 +20,7 @@ int is_leaf(struct node *tree) | ||
20 | return tree->fin||tree->fils[0]==NULL; | 20 | return tree->fin||tree->fils[0]==NULL; |
21 | } | 21 | } |
22 | 22 | ||
23 | -void add(struct node **tab_ptr_tree, char val[],int taille, int fl) | 23 | +void add(struct node **tab_ptr_tree, wchar_t val[],int taille, int fl) |
24 | { | 24 | { |
25 | if(tab_ptr_tree[fl]==NULL)cons_tree(&(tab_ptr_tree[fl]),val[0]+97); | 25 | if(tab_ptr_tree[fl]==NULL)cons_tree(&(tab_ptr_tree[fl]),val[0]+97); |
26 | Node* noeudtest = tab_ptr_tree[fl]; | 26 | Node* noeudtest = tab_ptr_tree[fl]; |
@@ -46,7 +46,7 @@ void add(struct node **tab_ptr_tree, char val[],int taille, int fl) | @@ -46,7 +46,7 @@ void add(struct node **tab_ptr_tree, char val[],int taille, int fl) | ||
46 | 46 | ||
47 | } | 47 | } |
48 | 48 | ||
49 | -int size(char val[]) | 49 | +int size(wchar_t val[]) |
50 | { | 50 | { |
51 | int cpt = 0; | 51 | int cpt = 0; |
52 | while(val[cpt]!='\0') | 52 | while(val[cpt]!='\0') |
@@ -56,7 +56,7 @@ int size(char val[]) | @@ -56,7 +56,7 @@ int size(char val[]) | ||
56 | return cpt; | 56 | return cpt; |
57 | } | 57 | } |
58 | 58 | ||
59 | -void toLowerCase(char mot[],int size) | 59 | +void toLowerCase(wchar_t mot[],int size) |
60 | { | 60 | { |
61 | for(int i=0;i<size;i++) | 61 | for(int i=0;i<size;i++) |
62 | { | 62 | { |
@@ -71,12 +71,13 @@ void toLowerCase(char mot[],int size) | @@ -71,12 +71,13 @@ void toLowerCase(char mot[],int size) | ||
71 | void load_tree(FILE *fp, struct node **tab_ptr_tree) | 71 | void load_tree(FILE *fp, struct node **tab_ptr_tree) |
72 | { | 72 | { |
73 | //fl (first letter) | 73 | //fl (first letter) |
74 | - char val[50]; | 74 | + wchar_t val[50]; |
75 | 75 | ||
76 | - while(fscanf(fp, "%s",val)==1) | 76 | + while(fwscanf(fp, L"%ls",val)==1) |
77 | { | 77 | { |
78 | int taille = size(val); | 78 | int taille = size(val); |
79 | toLowerCase(val,taille); | 79 | toLowerCase(val,taille); |
80 | + if(val[0]<'a' || val[0]>'z')continue; | ||
80 | //if(val[0]<97)val[0]+=32; | 81 | //if(val[0]<97)val[0]+=32; |
81 | //val[0]-=97; | 82 | //val[0]-=97; |
82 | add(tab_ptr_tree,val,taille,(int)val[0]-97); | 83 | add(tab_ptr_tree,val,taille,(int)val[0]-97); |
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | +#include <wchar.h> | ||
4 | +#include <locale.h> | ||
3 | 5 | ||
4 | typedef struct node { | 6 | typedef struct node { |
5 | - int val; | 7 | + wchar_t val; |
6 | int fin; | 8 | int fin; |
7 | int nbr_fils; | 9 | int nbr_fils; |
8 | struct node** fils; | 10 | struct node** fils; |
9 | }Node, *PtNode, *Tree; | 11 | }Node, *PtNode, *Tree; |
10 | 12 | ||
11 | -void cons_tree(struct node **, int); | 13 | +void cons_tree(struct node **, wchar_t); |
12 | 14 | ||
13 | void mk_empty_tree(struct node **); | 15 | void mk_empty_tree(struct node **); |
14 | 16 | ||
15 | int is_leaf(struct node *); | 17 | int is_leaf(struct node *); |
16 | 18 | ||
17 | -void add(struct node **, char* ,int ,int); | 19 | +void add(struct node **, wchar_t* ,int ,int); |
18 | 20 | ||
19 | void load_tree(FILE *, struct node **); | 21 | void load_tree(FILE *, struct node **); |
20 | 22 |