From 6c8b6d76d29ceef904e646aed87ebb609496497e Mon Sep 17 00:00:00 2001 From: pvernier Date: Wed, 10 Apr 2019 18:37:33 +0200 Subject: [PATCH] le debut des problemes --- projet0segfault.c | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/projet0segfault.c b/projet0segfault.c index db40c64..123fb53 100644 --- a/projet0segfault.c +++ b/projet0segfault.c @@ -14,19 +14,22 @@ struct cell { }; void initialisation_tab_arbre(struct node tab[]) { + for(int i = 0; i < A; i++) { - tab[i].lettre = 97+i; //ajout lettres minuscules + tab[i].lettre = 97+i; //ajout lettres minuscules + tab[i].listeFils = NULL; } + tab[A].lettre = 39; - /*for(int i = 0; i < 8; i++) { - tab[i+26].lettre = 130+i; //ajout caractères spéciaux - }*/ + tab[A].listeFils = NULL; + } void ajout_tete(char elem, struct cell** pL) { struct cell* p; + p = malloc(sizeof(struct cell)); - p->arbre = malloc(sizeof(struct node)); + //p->arbre = malloc(sizeof(struct node)); p->arbre->lettre = elem; p->arbreSuivant = *pL; *pL = p; @@ -41,16 +44,18 @@ void lien_listeFils(struct cell** pL) { struct cell* insertion(char elem, struct cell** pL) { printf("insert\n"); - printf("*pL : %d\n", *pL); + printf("*pL : %p\n", *pL); + printf("(*pL)->arbre : %p\n", &(*pL)->arbre); if((*pL == NULL)||((*pL)->arbre->lettre > elem)) { printf("condition1\n"); - lien_listeFils(pL); + //lien_listeFils(pL); ajout_tete(elem, pL); - printf("return insertion : %d\n", (*pL)->arbre->listeFils); + printf("return insertion : %p\n", (*pL)->arbre->listeFils); return (*pL)->arbre->listeFils; } else if((*pL)->arbre->lettre == elem) { printf("condition2\n"); return (*pL)->arbre->listeFils;} else {printf("esle\n"); insertion(elem, &(*pL)->arbreSuivant); } + } /*void affiche_tab(struct node tab[]) { @@ -60,24 +65,28 @@ struct cell* insertion(char elem, struct cell** pL) { }*/ void lire_fichier(FILE* fd, struct node tab_arbre_prcp[]) { + printf("entrer lire_fichier\n"); struct cell* localisationArbre; char motLu[50]; int i = 0; + printf("addressentré fd: %p\n", fd ); if(fd!=NULL) { + printf("fd!=NULL\n" ); while(fscanf(fd, "%s", motLu)==1) { + printf("entrer while\n"); if((motLu[i] >= 'a') && (motLu[i] <= 'z')) localisationArbre = tab_arbre_prcp[motLu[0]-97].listeFils; if(motLu[i] == 39) localisationArbre = tab_arbre_prcp[A].listeFils; //A = derniere case du tab - printf("avant while : localisation : %d\n", localisationArbre); + printf("avant while : localisation : %p\n", localisationArbre); while(motLu[i] != '\0') { i += 1; - printf("lettre lue : %c address : %d\n", motLu[i], localisationArbre); + printf("lettre lue : %c address : %p\n", motLu[i], localisationArbre); localisationArbre = insertion(motLu[i], &localisationArbre); - printf("localisation apres : %d\n", localisationArbre); + printf("localisation apres : %p\n", localisationArbre); printf("\n"); } printf("\n"); @@ -90,17 +99,23 @@ void lire_fichier(FILE* fd, struct node tab_arbre_prcp[]) { int main(int argc, char* argv[]) { FILE* fd; + fd=NULL; - struct node tab_arbre[A]; - struct node Arbre; - char lettre; - - if(argc>1) fd = fopen(argv[1], "r"); + struct node tab_arbre[A+1]; + //struct node Arbre; + //char lettre; + printf("etape1\n"); + + if(argc>1) fd = fopen(argv[1], "r"); - Arbre.listeFils = NULL; + printf("etape2\n"); initialisation_tab_arbre(tab_arbre); + + printf("tab_arbre[0].listeFils: %p \n", tab_arbre[0].listeFils); + + lire_fichier(fd, tab_arbre); - printf("tab_arbre[0].listeFils->arbre->lettre : %c\n", tab_arbre[3].listeFils->arbre->lettre); + printf("tab_arbre[0].listeFils->arbre->lettre : %c\n", tab_arbre[0].listeFils->arbre->lettre); //scanf("%c", &lettre); //insertion(lettre, &(Arbre.listeFils)); //printf("lettre : %c\n", Arbre.listeFils->arbre->lettre); -- libgit2 0.21.2