Commit 35b1737fb1c7a01184f442bad973340578469a16
0 parents
projet1.0
Showing
1 changed file
with
222 additions
and
0 deletions
Show diff stats
1 | +++ a/main.c | |
... | ... | @@ -0,0 +1,222 @@ |
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | +#define NBC 20 | |
4 | +#define NBO 40 | |
5 | +#define NBF 10 | |
6 | +#define LINE_MAX 1000 | |
7 | + | |
8 | + | |
9 | +#include <string.h> | |
10 | + | |
11 | + | |
12 | + | |
13 | +typedef struct Oeuvres Oeuvres; | |
14 | +struct Oeuvres | |
15 | +{ | |
16 | + char title[LINE_MAX]; | |
17 | + char annee[LINE_MAX]; | |
18 | + char commentaire[LINE_MAX]; | |
19 | + Oeuvres *suivant; | |
20 | + | |
21 | +}; | |
22 | + | |
23 | + | |
24 | +typedef Oeuvres *ptoeuvres, *liste_chaine; | |
25 | + | |
26 | + | |
27 | +typedef struct Realisateur Realisateur; | |
28 | +struct Realisateur | |
29 | +{ | |
30 | + char nom[LINE_MAX]; | |
31 | + char prenom[LINE_MAX]; | |
32 | + ptoeuvres filmographe; | |
33 | + Realisateur *suivant; | |
34 | +}; | |
35 | + | |
36 | +typedef Realisateur *ptrealisateur, *liste_realisateur; | |
37 | + | |
38 | +typedef struct | |
39 | +{ | |
40 | + Realisateur realisateur; | |
41 | + ptrealisateur suivant; | |
42 | + | |
43 | +}REALISATEUR; | |
44 | + | |
45 | + | |
46 | +int readPartOfLine(int a,int b,char line[LINE_MAX],char part[LINE_MAX]) | |
47 | +{ | |
48 | + | |
49 | + | |
50 | + int debut = a; | |
51 | + int endAv = b; | |
52 | + int av = 0; | |
53 | + while(debut < endAv) | |
54 | + { | |
55 | + | |
56 | + part[av] = line[debut]; | |
57 | + debut++; | |
58 | + av++; | |
59 | + } | |
60 | + part[av] = '\0'; | |
61 | + return debut; | |
62 | + | |
63 | +} | |
64 | +void readElement(char element[LINE_MAX],ptoeuvres film) | |
65 | +{ | |
66 | + | |
67 | + | |
68 | + | |
69 | + | |
70 | + int begin = 0; | |
71 | + if(element[0] == '\t') | |
72 | + begin = 2; | |
73 | + int Pbegin = strpbrk(element,"(") - element; | |
74 | + int Pend =strpbrk(element,")") - element; | |
75 | + int end = findEnd(element); | |
76 | + | |
77 | + readPartOfLine(begin,Pbegin,element,film->title); | |
78 | + | |
79 | + readPartOfLine(Pbegin+1,Pend,element,film->annee); | |
80 | + | |
81 | + readPartOfLine(Pend+1,end,element,film->commentaire); | |
82 | + printf("titre : %s , annee : %s , commentaire : %s \n",film->title,film->annee,film->commentaire); | |
83 | + | |
84 | + | |
85 | +} | |
86 | +int findEnd(char line[LINE_MAX]) | |
87 | +{ | |
88 | + int av = 0; | |
89 | + while(line[av] != '\n') | |
90 | + av++; | |
91 | + return av; | |
92 | +} | |
93 | +void initOeuvre(ptoeuvres oe) | |
94 | +{ | |
95 | + | |
96 | + | |
97 | + int e; | |
98 | + for(e = 0;e<LINE_MAX;e++) | |
99 | + { | |
100 | + oe->annee[e] = malloc(sizeof(char)); | |
101 | + oe->commentaire[e] = malloc(sizeof(char)); | |
102 | + oe->title[e] = malloc(sizeof(char)); | |
103 | + } | |
104 | + oe->suivant = malloc(sizeof(Oeuvres)); | |
105 | + | |
106 | + | |
107 | +} | |
108 | +void readFile(FILE *file, ptrealisateur database) | |
109 | +{ | |
110 | + | |
111 | + | |
112 | + char line[LINE_MAX]; | |
113 | + int av = 0; | |
114 | + | |
115 | + int first = 0; | |
116 | + | |
117 | + int virgule = 0; | |
118 | + int tab = 0; | |
119 | + int end = 0; | |
120 | + | |
121 | + char element[LINE_MAX]; | |
122 | + | |
123 | + | |
124 | + | |
125 | + ptrealisateur actualReal = database; | |
126 | + ptoeuvres actualOeuvre = NULL; | |
127 | + | |
128 | + | |
129 | + actualReal->filmographe = malloc(sizeof(Oeuvres)); | |
130 | + actualOeuvre = actualReal->filmographe; | |
131 | + | |
132 | + | |
133 | + | |
134 | + | |
135 | + | |
136 | + char *ret; | |
137 | + while(av == 0) | |
138 | + { | |
139 | + | |
140 | + if(fgets(line,LINE_MAX,file) != NULL) | |
141 | + { | |
142 | + | |
143 | + | |
144 | + ret = strpbrk(line,","); | |
145 | + if(ret != NULL) | |
146 | + { | |
147 | + | |
148 | + if(first == 1) | |
149 | + { | |
150 | + | |
151 | + actualReal->suivant = malloc(sizeof(Realisateur)); | |
152 | + actualReal = actualReal->suivant; | |
153 | + actualReal->filmographe = malloc(sizeof(Oeuvres)); | |
154 | + actualOeuvre = actualReal->filmographe; | |
155 | + initOeuvre(actualOeuvre); | |
156 | + } | |
157 | + | |
158 | + | |
159 | + first = 1; | |
160 | + | |
161 | + virgule = ret - line; | |
162 | + tab = strpbrk(line,"\t") - line; | |
163 | + end = findEnd(line); | |
164 | + readPartOfLine(0,virgule,line,actualReal->nom); | |
165 | + readPartOfLine(virgule+1,tab,line,actualReal->prenom); | |
166 | + | |
167 | + printf("nom : %s prenom : %s \n",actualReal->nom,actualReal->prenom); | |
168 | + | |
169 | + readPartOfLine(tab+1,end,line,element); | |
170 | + | |
171 | + readElement(element,actualOeuvre); | |
172 | + | |
173 | + | |
174 | + actualOeuvre = actualOeuvre->suivant; | |
175 | + | |
176 | + | |
177 | + | |
178 | + } | |
179 | + else if(strcmp(line,"\n") != 0) | |
180 | + { | |
181 | + | |
182 | + | |
183 | + | |
184 | + initOeuvre(actualOeuvre); | |
185 | + | |
186 | + | |
187 | + | |
188 | + readElement(line,actualOeuvre); | |
189 | + | |
190 | + actualOeuvre = actualOeuvre->suivant; | |
191 | + | |
192 | + | |
193 | + | |
194 | + } | |
195 | + | |
196 | + } | |
197 | + else | |
198 | + av = 1; | |
199 | + | |
200 | + | |
201 | + | |
202 | + } | |
203 | + | |
204 | +} | |
205 | + | |
206 | + | |
207 | +int main() | |
208 | +{ | |
209 | + | |
210 | + | |
211 | + Realisateur database; | |
212 | + ptrealisateur ptDataBase = &database; | |
213 | + database.filmographe = malloc(sizeof(Oeuvres)); | |
214 | + initOeuvre(database.filmographe); | |
215 | + FILE* fichier = NULL; | |
216 | + fichier = fopen("very_small_example.list", "r+"); | |
217 | + | |
218 | + readFile(fichier,ptDataBase); | |
219 | + | |
220 | + | |
221 | + return 0; | |
222 | +} | ... | ... |