#include #include #define A 27 struct node { char lettre; struct cell* listeFils; }; struct cell { struct node* arbre; struct cell* arbreSuivant; }; void lien_listeFils(struct cell** pL) { struct cell* p; p = malloc(sizeof(struct cell)); (*pL)->arbre->listeFils = p; } void initialisation_tab_arbre(struct node tab[]) { for(int i = 0; i < A-1; i++) { tab[i].lettre = 97+i; //ajout lettres minuscules tab[i].listeFils = NULL; } tab[A-1].lettre = 39; tab[A-1].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->lettre = elem; p->arbreSuivant = *pL; *pL = p; } struct cell * insertion(char elem, struct cell** pL) { if(((*pL) == NULL) || ((*pL)->arbre->lettre > elem)) { ajout_tete(elem, pL); return (*pL); } else if((*pL)->arbre->lettre == elem) { return (*pL); } else return insertion(elem, &(*pL)->arbreSuivant); } void lire_fichier(FILE* fd, struct node tab_arbre_prcp[]) { printf("lirefichier\n"); 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; } if(motLu[i] == 39) { printf("if(motLu[i] == 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); printf("\n"); } } printf("\n"); fclose(fd); printf("fin lire fichier\n"); } int main(int argc, char* argv[]) { FILE* fd; struct node tab_arbre[A]; if(argc>1) fd = fopen(argv[1], "r"); else fd = NULL; if (fd == NULL) { printf("Error : couldn't open file\n"); return 1; } initialisation_tab_arbre(tab_arbre); 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"); return 0; }