Commit ebd317c59ac816eee77eef7bdc9d895bfc84d509

Authored by mclaudel
1 parent 2d053d06

Projet modifié

Showing 1 changed file with 41 additions and 8 deletions   Show diff stats
@@ -90,7 +90,7 @@ void ajout_alphab(Node ** pn, char * mot,int cpt) @@ -90,7 +90,7 @@ void ajout_alphab(Node ** pn, char * mot,int cpt)
90 Node * charger_arbre(Node ** Arbre){ 90 Node * charger_arbre(Node ** Arbre){
91 FILE * dico; 91 FILE * dico;
92 char mot[MAX_LETTRES]; 92 char mot[MAX_LETTRES];
93 - dico = fopen("text.txt","r"); 93 + dico = fopen("test.txt","r");
94 int i; 94 int i;
95 while ((i = fscanf(dico,"%s",mot)) == 1){ 95 while ((i = fscanf(dico,"%s",mot)) == 1){
96 ajout_alphab(Arbre,mot,0); 96 ajout_alphab(Arbre,mot,0);
@@ -106,7 +106,7 @@ Node * charger_arbre(Node ** Arbre){ @@ -106,7 +106,7 @@ Node * charger_arbre(Node ** Arbre){
106 106
107 void affichage_arbre(Node * Arbre) 107 void affichage_arbre(Node * Arbre)
108 { 108 {
109 - if (Arbre->l == '?' && is_leaf(Arbre)){ 109 + if (is_empty(Arbre)){
110 printf("arbre vide \n"); 110 printf("arbre vide \n");
111 return; 111 return;
112 } 112 }
@@ -126,16 +126,13 @@ void affichage_arbre(Node * Arbre) @@ -126,16 +126,13 @@ void affichage_arbre(Node * Arbre)
126 126
127 void detruire_arbre(Node ** Arbre) 127 void detruire_arbre(Node ** Arbre)
128 { 128 {
129 - printf("---------- \n");  
130 - printf("%p \n",*Arbre); 129 +
131 if (is_empty(*Arbre)) return; 130 if (is_empty(*Arbre)) return;
132 - printf("%c \n",(*Arbre)->l);  
133 for (int i=0; i<size; i++){ 131 for (int i=0; i<size; i++){
134 detruire_arbre(&(*Arbre)->lettres[i]); 132 detruire_arbre(&(*Arbre)->lettres[i]);
135 } 133 }
136 free(*Arbre); 134 free(*Arbre);
137 - printf("suppression \n");  
138 - printf("%p \n",*Arbre); 135 + *Arbre=NULL;
139 } 136 }
140 137
141 138
@@ -147,10 +144,45 @@ void initialisation(Node ** Arbre){ @@ -147,10 +144,45 @@ void initialisation(Node ** Arbre){
147 Node *nouveau = malloc(sizeof(struct node)); 144 Node *nouveau = malloc(sizeof(struct node));
148 (*nouveau).l='?'; 145 (*nouveau).l='?';
149 for (int i=0; i<size; i++) nouveau->lettres[i] = NULL; 146 for (int i=0; i<size; i++) nouveau->lettres[i] = NULL;
150 - *Arbre = nouveau; 147 + *Arbre = nouveau;}
  148 +
  149 +
  150 +
  151 +
  152 +
  153 +
  154 +void comparaison(Node ** pn, char * mot,int cpt)
  155 +{
  156 + char lettre=mot[cpt];
  157 + int pos = lettre - 'a';
  158 + cpt++;
  159 + if (lettre == '\0'){
  160 + if((*pn).fin_de_mot=0) printf("erreur \n");
  161 + return;
  162 + }
  163 + if (tmp->lettres[pos] == NULL) {
  164 + printf("erreur \n");
  165 + }
  166 + return comparaison(&pn->lettres[pos],mot,cpt);
  167 +
  168 +
  169 +}
  170 +
  171 +void test_erreur(){
  172 + Node * Dico;
  173 + charger_arbre(&Dico);
  174 + FILE * texte;
  175 + char mot[MAX_LETTRES];
  176 + texte = fopen("texte.txt","r");
  177 + int i;
  178 + while ((i = fscanf(texte,"%s",mot)) == 1){
  179 + comparaison(&Dico,mot,0);
  180 + }
  181 + fclose(texte);
151 } 182 }
152 183
153 184
  185 +
154 186
155 187
156 188
@@ -162,5 +194,6 @@ int main(){ @@ -162,5 +194,6 @@ int main(){
162 printf("Arbre fini \n"); 194 printf("Arbre fini \n");
163 detruire_arbre(&Arbre); 195 detruire_arbre(&Arbre);
164 affichage_arbre(Arbre); 196 affichage_arbre(Arbre);
  197 + test_erreur();
165 return 0; 198 return 0;
166 } 199 }