Commit 73e92d24cbdb14c242bba6f89b955ab24519a877

Authored by vsalingu
1 parent 04b8ce94

Modifications de la fonction d'affichage

Showing 2 changed files with 23 additions and 15 deletions   Show diff stats
No preview for this file type
1 1 #include <stdio.h>
2 2 #include <stdlib.h>
3 3 #include <stdbool.h>
  4 +#include <string.h>
4 5  
5 6  
6 7 typedef struct cell* ptarbre;
... ... @@ -58,7 +59,7 @@ void ajout_dico(ptarbre *parbre, ptarbre *parbresuiv, char lettre)
58 59 printf("ajout lettre : %c à %p \n",(*parbresuiv)->lettre, parbresuiv);
59 60 }
60 61  
61   -void affiche_dico(ptarbre arbre)
  62 +void affiche_dico(ptarbre arbre, int n_lettre, char mot[])
62 63 // affiche tout le dictionnaire à partir de l'arbre (donc le numéro de lettre) sélectionné
63 64 {
64 65 if(arbre == NULL)
... ... @@ -67,17 +68,23 @@ void affiche_dico(ptarbre arbre)
67 68 }
68 69 else
69 70 {
70   - if (arbre->fils!=NULL)
  71 + if (arbre->fils != NULL)
71 72 {
72   - printf("%c\n", (arbre->lettre));
73   - while(arbre->suivant !=NULL)
74   - {
75   - printf("%c\n", (arbre->lettre));
76   - affiche_dico(arbre->fils);
77   - arbre=arbre->suivant;
78   - }
  73 + printf("%c",arbre->lettre);
  74 + mot[n_lettre]=arbre->lettre;
  75 + n_lettre++;
  76 + affiche_dico(arbre->fils,n_lettre,mot);
79 77 }
80   - }
  78 + printf("\n");
  79 + if (arbre->suivant != NULL)
  80 + {
  81 + printf("%s",mot);
  82 + affiche_dico(arbre->suivant, n_lettre, mot);
  83 + }
  84 + mot[n_lettre]=0;
  85 + n_lettre--;
  86 +
  87 + }
81 88  
82 89 }
83 90  
... ... @@ -101,7 +108,8 @@ int main()
101 108 ptarbre arbre_originel,arbre,arbre_prec;
102 109 arbre_originel=NULL;
103 110 arbre=NULL;
104   - char c,t;
  111 + char c,t, mot[30];
  112 + int n_lettre=0;
105 113 ptarbre rec;
106 114 // Ouvrir fichier
107 115 FILE *fp = fopen("words1.txt","r");
... ... @@ -133,10 +141,10 @@ int main()
133 141 {
134 142  
135 143 printf("rech suiv = NUll \n");
136   - ajout_dico(&(arbre),&(rec),c);
  144 + ajout_dico(&(arbre),&(rec->suivant),c);
137 145 // printf("ajout de : %c à %p et fils :%p\n", rec->lettre, rec, rec->fils);
138 146 arbre_prec=arbre;
139   - arbre=rec->fils;
  147 + arbre=rec->suivant->fils;
140 148 }
141 149  
142 150  
... ... @@ -159,14 +167,14 @@ int main()
159 167 arbre_prec->fin_mot=true; // Cette lettre est la dernière du mot
160 168 }
161 169  
162   - affiche_dico(arbre_originel);
  170 + affiche_dico(arbre_originel,n_lettre,mot);
163 171 printf("remise à 0\n");
164 172 arbre=arbre_originel; // On revient en haut de l'arbre pour commencer un nouveau mot
165 173 }
166 174 //arbre=arbre_originel;
167 175 }
168 176 printf("arbre originel lettre %c \n", arbre_originel->fils->lettre);
169   - affiche_dico(arbre_originel);
  177 + affiche_dico(arbre_originel,n_lettre,mot);
170 178 free_tree(&arbre);
171 179 fclose(fp);
172 180  
... ...