diff --git a/projet0segfault.c b/projet0segfault.c index 98285d8..47e8a98 100644 --- a/projet0segfault.c +++ b/projet0segfault.c @@ -33,51 +33,48 @@ void ajout_tete(char elem, struct cell** pL) { struct cell* p; p = malloc(sizeof(struct cell)); p->arbre = malloc(sizeof(struct node)); + p->arbre->listeFils = NULL; p->arbre->lettre = elem; p->arbreSuivant = *pL; *pL = p; } -struct cell * insertion(char elem, struct cell** pL) { +struct cell ** insertion(char elem, struct cell** pL) { if(((*pL) == NULL) || ((*pL)->arbre->lettre > elem)) { ajout_tete(elem, pL); - return (*pL); + return &(*pL)->arbre->listeFils; } else if((*pL)->arbre->lettre == elem) { - return (*pL); + return &(*pL)->arbre->listeFils; + } + else { + return insertion(elem, &(*pL)->arbreSuivant); } - else return insertion(elem, &(*pL)->arbreSuivant); } void lire_fichier(FILE* fd, struct node tab_arbre_prcp[]) { printf("lirefichier\n"); - struct cell* localisationArbre; + struct cell** localisationArbre; char motLu[50]; - while(fscanf(fd, "%s", motLu)==1) { - int i = 0; - printf("while lire fichier\n"); - if((motLu[i] >= 'a') && (motLu[i] <= 'z')) { - - printf("if((motLu[i] >= 'a') && (motLu[i] <= 'z'))\n"); - localisationArbre = tab_arbre_prcp[motLu[0]-97].listeFils; + int i = 0; + if((motLu[0] >= 'a') && (motLu[0] <= 'z')) { + localisationArbre = &tab_arbre_prcp[motLu[0]-97].listeFils; } - if(motLu[i] == 39) { - - printf("if(motLu[i] == 39)"); - localisationArbre = tab_arbre_prcp[A].listeFils; //A = derniere case du tab + if(motLu[0] == 39) { + localisationArbre = &tab_arbre_prcp[A].listeFils; //A = derniere case du tab } - - printf("avant while : localisation : %p\n", localisationArbre); while(motLu[i] != '\0') { i += 1; printf("lettre lue : %c address : %p\n", motLu[i], localisationArbre); - localisationArbre = insertion(motLu[i], &localisationArbre); - printf("localisation apres : %p\n", localisationArbre); + localisationArbre = insertion(motLu[i], localisationArbre); + printf("tab_arbre[%d].listeFils : %p\n",i, tab_arbre_prcp[i].listeFils); + /*printf("localisationArbre.lettre : %c\n", (*localisationArbre)->arbre->lettre); + printf("localisation apres : %p\n", localisationArbre);*/ printf("\n"); } } @@ -99,16 +96,18 @@ int main(int argc, char* argv[]) { printf("Error : couldn't open file\n"); return 1; } - - - initialisation_tab_arbre(tab_arbre); - + printf("avant init tab_arbre[1] %c\n", tab_arbre[1].lettre); + printf("fd : %p\n", fd); + initialisation_tab_arbre(tab_arbre); + printf("apres init tab_arbre[1] %c\n", tab_arbre[1].lettre); + printf("fd apres init : %p\n", fd); printf("avant lire fichier\n"); lire_fichier(fd, tab_arbre); - //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); - printf("avant return 0\n"); + printf("tab_arbre[0].lettre : %c\n", tab_arbre[0].lettre); + printf("tab_arbre[0].listeFils : %p\n", tab_arbre[0].listeFils); + printf("tab_arbre[0].listeFils->arbre : %p\n", tab_arbre[0].listeFils->arbre); + printf("tab_arbre[1].listeFils->arbre->lettre : %c\n", tab_arbre[0].listeFils->arbre->lettre); + printf("tab_arbre[0].listeFils->arbre->listeFils->arbre->lettre : %c\n", tab_arbre[0].listeFils->arbre->listeFils->arbre->lettre); + printf("tab_arbre[0].listeFils->arbre->listeFils->arbre->listeFils->arbre->lettre : %c\n", tab_arbre[0].listeFils->arbre->listeFils->arbre->listeFils->arbre->lettre); return 0; } -- libgit2 0.21.2