Commit 7bb61682e10f700767a864e569f133364e0c4e6e

Authored by pvernier
1 parent 4e905f52

sauvegarde au propre (menage)

Showing 1 changed file with 28 additions and 29 deletions   Show diff stats
@@ -33,51 +33,48 @@ void ajout_tete(char elem, struct cell** pL) { @@ -33,51 +33,48 @@ void ajout_tete(char elem, struct cell** pL) {
33 struct cell* p; 33 struct cell* p;
34 p = malloc(sizeof(struct cell)); 34 p = malloc(sizeof(struct cell));
35 p->arbre = malloc(sizeof(struct node)); 35 p->arbre = malloc(sizeof(struct node));
  36 + p->arbre->listeFils = NULL;
36 p->arbre->lettre = elem; 37 p->arbre->lettre = elem;
37 p->arbreSuivant = *pL; 38 p->arbreSuivant = *pL;
38 *pL = p; 39 *pL = p;
39 } 40 }
40 41
41 -struct cell * insertion(char elem, struct cell** pL) { 42 +struct cell ** insertion(char elem, struct cell** pL) {
42 if(((*pL) == NULL) || ((*pL)->arbre->lettre > elem)) { 43 if(((*pL) == NULL) || ((*pL)->arbre->lettre > elem)) {
43 ajout_tete(elem, pL); 44 ajout_tete(elem, pL);
44 - return (*pL); 45 + return &(*pL)->arbre->listeFils;
45 } 46 }
46 else if((*pL)->arbre->lettre == elem) { 47 else if((*pL)->arbre->lettre == elem) {
47 - return (*pL); 48 + return &(*pL)->arbre->listeFils;
  49 + }
  50 + else {
  51 + return insertion(elem, &(*pL)->arbreSuivant);
48 } 52 }
49 - else return insertion(elem, &(*pL)->arbreSuivant);  
50 } 53 }
51 54
52 55
53 void lire_fichier(FILE* fd, struct node tab_arbre_prcp[]) { 56 void lire_fichier(FILE* fd, struct node tab_arbre_prcp[]) {
54 57
55 printf("lirefichier\n"); 58 printf("lirefichier\n");
56 - struct cell* localisationArbre; 59 + struct cell** localisationArbre;
57 char motLu[50]; 60 char motLu[50];
58 -  
59 while(fscanf(fd, "%s", motLu)==1) { 61 while(fscanf(fd, "%s", motLu)==1) {
60 - int i = 0;  
61 - printf("while lire fichier\n");  
62 - if((motLu[i] >= 'a') && (motLu[i] <= 'z')) {  
63 -  
64 - printf("if((motLu[i] >= 'a') && (motLu[i] <= 'z'))\n");  
65 - localisationArbre = tab_arbre_prcp[motLu[0]-97].listeFils; 62 + int i = 0;
  63 + if((motLu[0] >= 'a') && (motLu[0] <= 'z')) {
  64 + localisationArbre = &tab_arbre_prcp[motLu[0]-97].listeFils;
66 } 65 }
67 66
68 - if(motLu[i] == 39) {  
69 -  
70 - printf("if(motLu[i] == 39)");  
71 - localisationArbre = tab_arbre_prcp[A].listeFils; //A = derniere case du tab 67 + if(motLu[0] == 39) {
  68 + localisationArbre = &tab_arbre_prcp[A].listeFils; //A = derniere case du tab
72 } 69 }
73 -  
74 - printf("avant while : localisation : %p\n", localisationArbre);  
75 while(motLu[i] != '\0') { 70 while(motLu[i] != '\0') {
76 71
77 i += 1; 72 i += 1;
78 printf("lettre lue : %c address : %p\n", motLu[i], localisationArbre); 73 printf("lettre lue : %c address : %p\n", motLu[i], localisationArbre);
79 - localisationArbre = insertion(motLu[i], &localisationArbre);  
80 - printf("localisation apres : %p\n", localisationArbre); 74 + localisationArbre = insertion(motLu[i], localisationArbre);
  75 + printf("tab_arbre[%d].listeFils : %p\n",i, tab_arbre_prcp[i].listeFils);
  76 + /*printf("localisationArbre.lettre : %c\n", (*localisationArbre)->arbre->lettre);
  77 + printf("localisation apres : %p\n", localisationArbre);*/
81 printf("\n"); 78 printf("\n");
82 } 79 }
83 } 80 }
@@ -99,16 +96,18 @@ int main(int argc, char* argv[]) { @@ -99,16 +96,18 @@ int main(int argc, char* argv[]) {
99 printf("Error : couldn't open file\n"); 96 printf("Error : couldn't open file\n");
100 return 1; 97 return 1;
101 } 98 }
102 -  
103 -  
104 - initialisation_tab_arbre(tab_arbre);  
105 - 99 + printf("avant init tab_arbre[1] %c\n", tab_arbre[1].lettre);
  100 + printf("fd : %p\n", fd);
  101 + initialisation_tab_arbre(tab_arbre);
  102 + printf("apres init tab_arbre[1] %c\n", tab_arbre[1].lettre);
  103 + printf("fd apres init : %p\n", fd);
106 printf("avant lire fichier\n"); 104 printf("avant lire fichier\n");
107 lire_fichier(fd, tab_arbre); 105 lire_fichier(fd, tab_arbre);
108 - //printf("tab_arbre[0].listeFils->arbre->lettre : %c\n", tab_arbre[0].listeFils->arbre->lettre);  
109 - //scanf("%c", &lettre);  
110 - //insertion(lettre, &(Arbre.listeFils));  
111 - //printf("lettre : %c\n", Arbre.listeFils->arbre->lettre);  
112 - printf("avant return 0\n"); 106 + printf("tab_arbre[0].lettre : %c\n", tab_arbre[0].lettre);
  107 + printf("tab_arbre[0].listeFils : %p\n", tab_arbre[0].listeFils);
  108 + printf("tab_arbre[0].listeFils->arbre : %p\n", tab_arbre[0].listeFils->arbre);
  109 + printf("tab_arbre[1].listeFils->arbre->lettre : %c\n", tab_arbre[0].listeFils->arbre->lettre);
  110 + printf("tab_arbre[0].listeFils->arbre->listeFils->arbre->lettre : %c\n", tab_arbre[0].listeFils->arbre->listeFils->arbre->lettre);
  111 + printf("tab_arbre[0].listeFils->arbre->listeFils->arbre->listeFils->arbre->lettre : %c\n", tab_arbre[0].listeFils->arbre->listeFils->arbre->listeFils->arbre->lettre);
113 return 0; 112 return 0;
114 } 113 }