Commit 6c8b6d76d29ceef904e646aed87ebb609496497e

Authored by pvernier
1 parent 893dbc98

le debut des problemes

Showing 1 changed file with 33 additions and 18 deletions   Show diff stats
@@ -14,19 +14,22 @@ struct cell { @@ -14,19 +14,22 @@ struct cell {
14 }; 14 };
15 15
16 void initialisation_tab_arbre(struct node tab[]) { 16 void initialisation_tab_arbre(struct node tab[]) {
  17 +
17 for(int i = 0; i < A; i++) { 18 for(int i = 0; i < A; i++) {
18 - tab[i].lettre = 97+i; //ajout lettres minuscules 19 + tab[i].lettre = 97+i; //ajout lettres minuscules
  20 + tab[i].listeFils = NULL;
19 } 21 }
  22 +
20 tab[A].lettre = 39; 23 tab[A].lettre = 39;
21 - /*for(int i = 0; i < 8; i++) {  
22 - tab[i+26].lettre = 130+i; //ajout caractères spéciaux  
23 - }*/ 24 + tab[A].listeFils = NULL;
  25 +
24 } 26 }
25 27
26 void ajout_tete(char elem, struct cell** pL) { 28 void ajout_tete(char elem, struct cell** pL) {
27 struct cell* p; 29 struct cell* p;
  30 +
28 p = malloc(sizeof(struct cell)); 31 p = malloc(sizeof(struct cell));
29 - p->arbre = malloc(sizeof(struct node)); 32 + //p->arbre = malloc(sizeof(struct node));
30 p->arbre->lettre = elem; 33 p->arbre->lettre = elem;
31 p->arbreSuivant = *pL; 34 p->arbreSuivant = *pL;
32 *pL = p; 35 *pL = p;
@@ -41,16 +44,18 @@ void lien_listeFils(struct cell** pL) { @@ -41,16 +44,18 @@ void lien_listeFils(struct cell** pL) {
41 44
42 struct cell* insertion(char elem, struct cell** pL) { 45 struct cell* insertion(char elem, struct cell** pL) {
43 printf("insert\n"); 46 printf("insert\n");
44 - printf("*pL : %d\n", *pL); 47 + printf("*pL : %p\n", *pL);
  48 + printf("(*pL)->arbre : %p\n", &(*pL)->arbre);
45 if((*pL == NULL)||((*pL)->arbre->lettre > elem)) { 49 if((*pL == NULL)||((*pL)->arbre->lettre > elem)) {
46 printf("condition1\n"); 50 printf("condition1\n");
47 - lien_listeFils(pL); 51 + //lien_listeFils(pL);
48 ajout_tete(elem, pL); 52 ajout_tete(elem, pL);
49 - printf("return insertion : %d\n", (*pL)->arbre->listeFils); 53 + printf("return insertion : %p\n", (*pL)->arbre->listeFils);
50 return (*pL)->arbre->listeFils; 54 return (*pL)->arbre->listeFils;
51 } 55 }
52 else if((*pL)->arbre->lettre == elem) { printf("condition2\n"); return (*pL)->arbre->listeFils;} 56 else if((*pL)->arbre->lettre == elem) { printf("condition2\n"); return (*pL)->arbre->listeFils;}
53 else {printf("esle\n"); insertion(elem, &(*pL)->arbreSuivant); } 57 else {printf("esle\n"); insertion(elem, &(*pL)->arbreSuivant); }
  58 +
54 } 59 }
55 60
56 /*void affiche_tab(struct node tab[]) { 61 /*void affiche_tab(struct node tab[]) {
@@ -60,24 +65,28 @@ struct cell* insertion(char elem, struct cell** pL) { @@ -60,24 +65,28 @@ struct cell* insertion(char elem, struct cell** pL) {
60 }*/ 65 }*/
61 66
62 void lire_fichier(FILE* fd, struct node tab_arbre_prcp[]) { 67 void lire_fichier(FILE* fd, struct node tab_arbre_prcp[]) {
  68 + printf("entrer lire_fichier\n");
63 struct cell* localisationArbre; 69 struct cell* localisationArbre;
64 char motLu[50]; 70 char motLu[50];
65 int i = 0; 71 int i = 0;
  72 + printf("addressentré fd: %p\n", fd );
66 if(fd!=NULL) 73 if(fd!=NULL)
67 { 74 {
  75 + printf("fd!=NULL\n" );
68 while(fscanf(fd, "%s", motLu)==1) 76 while(fscanf(fd, "%s", motLu)==1)
69 { 77 {
  78 + printf("entrer while\n");
70 if((motLu[i] >= 'a') && (motLu[i] <= 'z')) localisationArbre = tab_arbre_prcp[motLu[0]-97].listeFils; 79 if((motLu[i] >= 'a') && (motLu[i] <= 'z')) localisationArbre = tab_arbre_prcp[motLu[0]-97].listeFils;
71 80
72 if(motLu[i] == 39) localisationArbre = tab_arbre_prcp[A].listeFils; //A = derniere case du tab 81 if(motLu[i] == 39) localisationArbre = tab_arbre_prcp[A].listeFils; //A = derniere case du tab
73 82
74 - printf("avant while : localisation : %d\n", localisationArbre); 83 + printf("avant while : localisation : %p\n", localisationArbre);
75 while(motLu[i] != '\0') 84 while(motLu[i] != '\0')
76 { 85 {
77 i += 1; 86 i += 1;
78 - printf("lettre lue : %c address : %d\n", motLu[i], localisationArbre); 87 + printf("lettre lue : %c address : %p\n", motLu[i], localisationArbre);
79 localisationArbre = insertion(motLu[i], &localisationArbre); 88 localisationArbre = insertion(motLu[i], &localisationArbre);
80 - printf("localisation apres : %d\n", localisationArbre); 89 + printf("localisation apres : %p\n", localisationArbre);
81 printf("\n"); 90 printf("\n");
82 } 91 }
83 printf("\n"); 92 printf("\n");
@@ -90,17 +99,23 @@ void lire_fichier(FILE* fd, struct node tab_arbre_prcp[]) { @@ -90,17 +99,23 @@ void lire_fichier(FILE* fd, struct node tab_arbre_prcp[]) {
90 99
91 int main(int argc, char* argv[]) { 100 int main(int argc, char* argv[]) {
92 FILE* fd; 101 FILE* fd;
  102 + fd=NULL;
93 103
94 - struct node tab_arbre[A];  
95 - struct node Arbre;  
96 - char lettre;  
97 -  
98 - if(argc>1) fd = fopen(argv[1], "r"); 104 + struct node tab_arbre[A+1];
  105 + //struct node Arbre;
  106 + //char lettre;
  107 + printf("etape1\n");
  108 +
  109 + if(argc>1) fd = fopen(argv[1], "r");
99 110
100 - Arbre.listeFils = NULL; 111 + printf("etape2\n");
101 initialisation_tab_arbre(tab_arbre); 112 initialisation_tab_arbre(tab_arbre);
  113 +
  114 + printf("tab_arbre[0].listeFils: %p \n", tab_arbre[0].listeFils);
  115 +
  116 +
102 lire_fichier(fd, tab_arbre); 117 lire_fichier(fd, tab_arbre);
103 - printf("tab_arbre[0].listeFils->arbre->lettre : %c\n", tab_arbre[3].listeFils->arbre->lettre); 118 + printf("tab_arbre[0].listeFils->arbre->lettre : %c\n", tab_arbre[0].listeFils->arbre->lettre);
104 //scanf("%c", &lettre); 119 //scanf("%c", &lettre);
105 //insertion(lettre, &(Arbre.listeFils)); 120 //insertion(lettre, &(Arbre.listeFils));
106 //printf("lettre : %c\n", Arbre.listeFils->arbre->lettre); 121 //printf("lettre : %c\n", Arbre.listeFils->arbre->lettre);