Commit 9dea5cd404ef15559afc6007dd38725d47f26e2b
1 parent
653f7357
suppression
Showing
1 changed file
with
0 additions
and
113 deletions
Show diff stats
projet0segfault.c deleted
@@ -1,113 +0,0 @@ | @@ -1,113 +0,0 @@ | ||
1 | -#include <stdio.h> | ||
2 | -#include <stdlib.h> | ||
3 | - | ||
4 | -#define A 27 | ||
5 | - | ||
6 | -struct node { | ||
7 | - char lettre; | ||
8 | - struct cell* listeFils; | ||
9 | -}; | ||
10 | - | ||
11 | -struct cell { | ||
12 | - struct node* arbre; | ||
13 | - struct cell* arbreSuivant; | ||
14 | -}; | ||
15 | - | ||
16 | -void lien_listeFils(struct cell** pL) { | ||
17 | - struct cell* p; | ||
18 | - p = malloc(sizeof(struct cell)); | ||
19 | - | ||
20 | - (*pL)->arbre->listeFils = p; | ||
21 | -} | ||
22 | - | ||
23 | -void initialisation_tab_arbre(struct node tab[]) { | ||
24 | - for(int i = 0; i < A-1; i++) { | ||
25 | - tab[i].lettre = 97+i; //ajout lettres minuscules | ||
26 | - tab[i].listeFils = NULL; | ||
27 | - } | ||
28 | - tab[A-1].lettre = 39; | ||
29 | - tab[A-1].listeFils = NULL; | ||
30 | -} | ||
31 | - | ||
32 | -void ajout_tete(char elem, struct cell** pL) { | ||
33 | - struct cell* p; | ||
34 | - p = malloc(sizeof(struct cell)); | ||
35 | - p->arbre = malloc(sizeof(struct node)); | ||
36 | - p->arbre->listeFils = NULL; | ||
37 | - p->arbre->lettre = elem; | ||
38 | - p->arbreSuivant = *pL; | ||
39 | - *pL = p; | ||
40 | -} | ||
41 | - | ||
42 | -struct cell ** insertion(char elem, struct cell** pL) { | ||
43 | - if(((*pL) == NULL) || ((*pL)->arbre->lettre > elem)) { | ||
44 | - ajout_tete(elem, pL); | ||
45 | - return &(*pL)->arbre->listeFils; | ||
46 | - } | ||
47 | - else if((*pL)->arbre->lettre == elem) { | ||
48 | - return &(*pL)->arbre->listeFils; | ||
49 | - } | ||
50 | - else { | ||
51 | - return insertion(elem, &(*pL)->arbreSuivant); | ||
52 | - } | ||
53 | -} | ||
54 | - | ||
55 | - | ||
56 | -void lire_fichier(FILE* fd, struct node tab_arbre_prcp[]) { | ||
57 | - | ||
58 | - printf("lirefichier\n"); | ||
59 | - struct cell** localisationArbre; | ||
60 | - char motLu[50]; | ||
61 | - while(fscanf(fd, "%s", motLu)==1) { | ||
62 | - int i = 0; | ||
63 | - if((motLu[0] >= 'a') && (motLu[0] <= 'z')) { | ||
64 | - localisationArbre = &tab_arbre_prcp[motLu[0]-97].listeFils; | ||
65 | - } | ||
66 | - | ||
67 | - if(motLu[0] == 39) { | ||
68 | - localisationArbre = &tab_arbre_prcp[A].listeFils; //A = derniere case du tab | ||
69 | - } | ||
70 | - while(motLu[i] != '\0') { | ||
71 | - | ||
72 | - i += 1; | ||
73 | - printf("lettre lue : %c address : %p\n", motLu[i], 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);*/ | ||
78 | - printf("\n"); | ||
79 | - } | ||
80 | - } | ||
81 | - printf("\n"); | ||
82 | - fclose(fd); | ||
83 | - | ||
84 | - printf("fin lire fichier\n"); | ||
85 | - | ||
86 | -} | ||
87 | - | ||
88 | - | ||
89 | -int main(int argc, char* argv[]) { | ||
90 | - FILE* fd; | ||
91 | - struct node tab_arbre[A]; | ||
92 | - | ||
93 | - if(argc>1) fd = fopen(argv[1], "r"); | ||
94 | - else fd = NULL; | ||
95 | - if (fd == NULL) { | ||
96 | - printf("Error : couldn't open file\n"); | ||
97 | - return 1; | ||
98 | - } | ||
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); | ||
104 | - printf("avant lire fichier\n"); | ||
105 | - lire_fichier(fd, tab_arbre); | ||
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); | ||
112 | - return 0; | ||
113 | -} |