Commit 7d2c7bff31b2e3b5c56193d034c1ca5819735fae

Authored by rsSimonin
1 parent 6140ed2a

implementation de la gestion des accents et de s majuscules

Showing 1 changed file with 29 additions and 23 deletions   Show diff stats
... ... @@ -3,26 +3,30 @@
3 3 #include <stdbool.h>
4 4 #include <string.h>
5 5  
  6 +#define TAILLE 27
6 7  
7 8 typedef struct arbre{
8 9 char val;
9   - struct arbre *suite[26];
  10 + struct arbre *suite[TAILLE];
10 11 bool finmot; //1 si fin de mot
11 12 }Arbre;
12 13  
13 14 typedef struct dico {
14   - Arbre *alpha[26];
  15 + Arbre *alpha[TAILLE];
15 16 }Dico;
16 17  
17 18  
18 19  
19 20 int calculcase(char c){
  21 + if(c==39){
  22 + return 26;
  23 + }
  24 + else if(c<97){
  25 + return c-'A';
  26 + }
  27 + else {
20 28 return c-'a';
21   -}
22   -
23   -void arbre_vide(struct arbre ** pt_arbre)
24   -{
25   - *pt_arbre = NULL;
  29 + }
26 30 }
27 31  
28 32 bool est_vide(struct arbre *arbre)
... ... @@ -37,11 +41,21 @@ bool fin_de_mot(struct arbre *arbre)
37 41  
38 42 void ini_dico(struct dico * pt_dico){
39 43 printf("ini_dico\n");
40   - for(int i=0;i<26;i++){
  44 + for(int i=0;i<TAILLE;i++){
41 45 pt_dico->alpha[i]=NULL;
42 46 }
43 47 }
44   -
  48 +void creation_arbre(Arbre **ppt_arbre,char c){
  49 + printf("creation arbre\n");
  50 + Arbre *monarbre=malloc(sizeof(struct arbre));
  51 + monarbre->val=c;
  52 + monarbre->finmot=false;
  53 + for(int j=0;j<TAILLE;j++){
  54 + monarbre->suite[j]=NULL;
  55 + }
  56 + *ppt_arbre=monarbre;
  57 +}
  58 +
45 59  
46 60 void ajout_mot(struct arbre **arbrecourant,char *mot,int i){
47 61  
... ... @@ -50,15 +64,7 @@ void ajout_mot(struct arbre **arbrecourant,char *mot,int i){
50 64 if(mot[i]!='\0'){
51 65 printf("\nlettre:%c; i=%d\n",mot[i],i);
52 66 if (*arbrecourant==NULL){
53   -
54   - printf("creation arbre\n");
55   - Arbre *monarbre=malloc(sizeof(struct arbre));
56   - monarbre->val=mot[i];
57   - monarbre->finmot=false;
58   - for(int j=0;j<26;j++){
59   - monarbre->suite[j]=NULL;
60   - }
61   - *arbrecourant=monarbre;
  67 + creation_arbre(arbrecourant,mot[i]);
62 68 }
63 69 i++;
64 70 ajout_mot(&((*arbrecourant)->suite[calculcase(mot[i])]),mot,i);
... ... @@ -82,7 +88,7 @@ void free_arbre(struct arbre *pt_arbre){
82 88 if (pt_arbre==NULL){
83 89 return ;
84 90 }
85   - for(int i=0;i<26;i++){
  91 + for(int i=0;i<TAILLE;i++){
86 92 free_arbre((pt_arbre->suite[i]));
87 93 }
88 94 free(pt_arbre);
... ... @@ -93,7 +99,7 @@ void free_dico(struct dico *pt_dico){
93 99 return ;
94 100 }
95 101  
96   - for(int i=0;i<26;i++){
  102 + for(int i=0;i<TAILLE;i++){
97 103 free_arbre((pt_dico->alpha[i]));
98 104 }
99 105  
... ... @@ -105,7 +111,7 @@ void affiche_arbre(struct arbre *arbre){
105 111 return ;
106 112 }
107 113 printf("%c:",arbre->val);
108   - for(int i=0;i<26;i++){
  114 + for(int i=0;i<TAILLE;i++){
109 115 affiche_arbre(arbre->suite[i]);
110 116 }
111 117 }
... ... @@ -115,7 +121,7 @@ void affiche_dico(struct dico *dico){
115 121 return ;
116 122 }
117 123 printf("---------------------------------------\n");
118   - for(int i=0;i<26;i++){
  124 + for(int i=0;i<TAILLE;i++){
119 125 printf("%d:",i);
120 126 affiche_arbre(dico->alpha[i]);
121 127 printf("\n");
... ... @@ -125,7 +131,7 @@ void affiche_dico(struct dico *dico){
125 131  
126 132  
127 133 int main (){
128   - FILE* fp = fopen("dicotest.txt","r"); //amelioration entrée
  134 + FILE* fp = fopen("words-no-accents","r"); //amelioration entrée
129 135 if(fp == NULL){ return EXIT_FAILURE;} //File is not readable
130 136  
131 137 struct dico *mondico=malloc(sizeof(struct dico));
... ...