Commit 38be3329e5bb64c851e9160e01034e1b71333fea
1 parent
7d2c7bff
makefile et main
Showing
1 changed file
with
42 additions
and
35 deletions
Show diff stats
arbre.c
1 | -#include <stdio.h> | |
2 | -#include <stdlib.h> | |
3 | -#include <stdbool.h> | |
4 | -#include <string.h> | |
1 | +#include "arbre.h" | |
5 | 2 | |
6 | -#define TAILLE 27 | |
7 | 3 | |
8 | -typedef struct arbre{ | |
9 | - char val; | |
10 | - struct arbre *suite[TAILLE]; | |
11 | - bool finmot; //1 si fin de mot | |
12 | -}Arbre; | |
4 | +// typedef struct arbre{ | |
5 | +// char val; | |
6 | +// struct arbre *suite[TAILLE]; | |
7 | +// bool finmot; //1 si fin de mot | |
8 | +// }Arbre; | |
9 | +// | |
10 | +// typedef struct dico { | |
11 | +// Arbre *alpha[TAILLE]; | |
12 | +// }Dico; | |
13 | 13 | |
14 | -typedef struct dico { | |
15 | - Arbre *alpha[TAILLE]; | |
16 | -}Dico; | |
17 | 14 | |
18 | 15 | |
19 | - | |
20 | -int calculcase(char c){ | |
16 | +int calculcase(char c) | |
17 | +{ | |
21 | 18 | if(c==39){ |
22 | 19 | return 26; |
23 | 20 | } |
... | ... | @@ -39,13 +36,15 @@ bool fin_de_mot(struct arbre *arbre) |
39 | 36 | return arbre->finmot; |
40 | 37 | } |
41 | 38 | |
42 | -void ini_dico(struct dico * pt_dico){ | |
39 | +void ini_dico(struct dico *pt_dico) | |
40 | +{ | |
43 | 41 | printf("ini_dico\n"); |
44 | 42 | for(int i=0;i<TAILLE;i++){ |
45 | 43 | pt_dico->alpha[i]=NULL; |
46 | 44 | } |
47 | 45 | } |
48 | -void creation_arbre(Arbre **ppt_arbre,char c){ | |
46 | +void creation_arbre(Arbre **ppt_arbre,char c) | |
47 | +{ | |
49 | 48 | printf("creation arbre\n"); |
50 | 49 | Arbre *monarbre=malloc(sizeof(struct arbre)); |
51 | 50 | monarbre->val=c; |
... | ... | @@ -57,7 +56,8 @@ void creation_arbre(Arbre **ppt_arbre,char c){ |
57 | 56 | } |
58 | 57 | |
59 | 58 | |
60 | -void ajout_mot(struct arbre **arbrecourant,char *mot,int i){ | |
59 | +void ajout_mot(struct arbre **arbrecourant,char *mot,int i) | |
60 | +{ | |
61 | 61 | |
62 | 62 | printf("%s:length:%zu \n",mot,strlen(mot)); |
63 | 63 | |
... | ... | @@ -67,6 +67,9 @@ void ajout_mot(struct arbre **arbrecourant,char *mot,int i){ |
67 | 67 | creation_arbre(arbrecourant,mot[i]); |
68 | 68 | } |
69 | 69 | i++; |
70 | + if(mot[i]!='\0'){ | |
71 | + (*arbrecourant)->finmot=true; | |
72 | + } | |
70 | 73 | ajout_mot(&((*arbrecourant)->suite[calculcase(mot[i])]),mot,i); |
71 | 74 | } |
72 | 75 | |
... | ... | @@ -84,7 +87,8 @@ void charger_arbre(FILE *fp, struct dico **ppt_dico) |
84 | 87 | } |
85 | 88 | |
86 | 89 | |
87 | -void free_arbre(struct arbre *pt_arbre){ | |
90 | +void free_arbre(struct arbre *pt_arbre) | |
91 | +{ | |
88 | 92 | if (pt_arbre==NULL){ |
89 | 93 | return ; |
90 | 94 | } |
... | ... | @@ -94,7 +98,8 @@ void free_arbre(struct arbre *pt_arbre){ |
94 | 98 | free(pt_arbre); |
95 | 99 | } |
96 | 100 | |
97 | -void free_dico(struct dico *pt_dico){ | |
101 | +void free_dico(struct dico *pt_dico) | |
102 | +{ | |
98 | 103 | if (pt_dico==NULL){ |
99 | 104 | return ; |
100 | 105 | } |
... | ... | @@ -106,7 +111,8 @@ void free_dico(struct dico *pt_dico){ |
106 | 111 | free(pt_dico); |
107 | 112 | } |
108 | 113 | |
109 | -void affiche_arbre(struct arbre *arbre){ | |
114 | +void affiche_arbre(struct arbre *arbre) | |
115 | +{ | |
110 | 116 | if(arbre==NULL){ |
111 | 117 | return ; |
112 | 118 | } |
... | ... | @@ -116,7 +122,8 @@ void affiche_arbre(struct arbre *arbre){ |
116 | 122 | } |
117 | 123 | } |
118 | 124 | |
119 | -void affiche_dico(struct dico *dico){ | |
125 | +void affiche_dico(struct dico *dico) | |
126 | +{ | |
120 | 127 | if(dico==NULL){ |
121 | 128 | return ; |
122 | 129 | } |
... | ... | @@ -130,16 +137,16 @@ void affiche_dico(struct dico *dico){ |
130 | 137 | } |
131 | 138 | |
132 | 139 | |
133 | -int main (){ | |
134 | - FILE* fp = fopen("words-no-accents","r"); //amelioration entrée | |
135 | - if(fp == NULL){ return EXIT_FAILURE;} //File is not readable | |
136 | - | |
137 | - struct dico *mondico=malloc(sizeof(struct dico)); | |
138 | - charger_arbre(fp,&mondico); | |
139 | - affiche_dico(mondico); | |
140 | - | |
141 | - | |
142 | - free_dico(mondico); | |
143 | - fclose(fp); | |
144 | - return 0; | |
145 | -} | |
140 | +// int main (){ | |
141 | +// FILE* fp = fopen("words-no-accents","r"); //amelioration entrée | |
142 | +// if(fp == NULL){ return EXIT_FAILURE;} //File is not readable | |
143 | +// | |
144 | +// struct dico *mondico=malloc(sizeof(struct dico)); | |
145 | +// charger_arbre(fp,&mondico); | |
146 | +// affiche_dico(mondico); | |
147 | +// | |
148 | +// | |
149 | +// free_dico(mondico); | |
150 | +// fclose(fp); | |
151 | +// return 0; | |
152 | +// } | ... | ... |