Commit 64179f09a96752390955c49bdbeb5be25dad5275
1 parent
67e3cd7b
programme ajout elements dand liste
Showing
1 changed file
with
187 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,187 @@ |
1 | +//By Bianca and Mathis | |
2 | + | |
3 | +//Ce programme permet : | |
4 | +//Avec un tableau de char[] donné peut créer une personne et l'ajouter a une liste. | |
5 | + | |
6 | +#include <stdio.h> | |
7 | +#include <stdlib.h> | |
8 | +#include <stdbool.h> | |
9 | +#include <string.h> | |
10 | +#include <ctype.h> | |
11 | + | |
12 | + | |
13 | +//Le struct de personne: | |
14 | +typedef struct Personne Personne; | |
15 | +struct Personne { | |
16 | + int athId; | |
17 | + int regId; | |
18 | + int divId; | |
19 | + char* lastName; | |
20 | + char* firstName; | |
21 | + char gender; | |
22 | + int age; | |
23 | + char* weight; | |
24 | + char* height; | |
25 | + int affiliateId; | |
26 | + char* affiliateName; | |
27 | + int overallScrore; | |
28 | + int overallRank; | |
29 | + int score18_1; | |
30 | + char* scoreDisplay18_1; | |
31 | + int rank18_1; | |
32 | + int score18_2; | |
33 | + char* scoreDisplay18_2; | |
34 | + int rank18_2; | |
35 | + int score18_2a; | |
36 | + char* scoreDisplay18_2a; | |
37 | + int rank18_2a; | |
38 | + int score18_3; | |
39 | + char* scoreDisplay18_3; | |
40 | + int rank18_3; | |
41 | + int score18_4; | |
42 | + char* scoreDisplay18_4; | |
43 | + int rank18_4; | |
44 | + int score18_5; | |
45 | + char* scoreDisplay18_5; | |
46 | + int rank18_5; | |
47 | + Personne* suivant;}; | |
48 | + | |
49 | +typedef Personne* Liste; | |
50 | + | |
51 | + | |
52 | + | |
53 | +/************************************************************************/ | |
54 | +//Gestion de listes | |
55 | +void ajout_tete(Liste *l, Personne P) | |
56 | +{ | |
57 | + Personne *p; | |
58 | + p= malloc(sizeof(Personne)); | |
59 | + | |
60 | + p->athId = P.athId; | |
61 | + p->regId = P.regId; | |
62 | + p->divId = P.divId; | |
63 | + p->lastName = P.lastName; | |
64 | + p->firstName = P.firstName; | |
65 | + p->gender = P.gender; | |
66 | + p->age = P.age; | |
67 | + p->weight = P.weight; | |
68 | + p->height = P.height; | |
69 | + p->affiliateId = P.affiliateId; | |
70 | + p->affiliateName = P.affiliateName; | |
71 | + p->overallScrore = P.overallScrore; | |
72 | + p->overallRank = P.overallRank; | |
73 | + p->score18_1 = P.score18_1; | |
74 | + p->scoreDisplay18_1 = P.scoreDisplay18_1; | |
75 | + p->rank18_1 = P.rank18_1; | |
76 | + p->score18_2 = P.score18_2; | |
77 | + p->scoreDisplay18_2 = P.scoreDisplay18_2; | |
78 | + p->rank18_2 = P.rank18_2; | |
79 | + p->score18_2a = P.score18_2a; | |
80 | + p->scoreDisplay18_2a = P.scoreDisplay18_2a; | |
81 | + p->rank18_2a = P.rank18_2a; | |
82 | + p->score18_3 = P.score18_3; | |
83 | + p->scoreDisplay18_3 = P.scoreDisplay18_3; | |
84 | + p->rank18_3 = P.rank18_3; | |
85 | + p->score18_4 = P.score18_4; | |
86 | + p->scoreDisplay18_4 = P.scoreDisplay18_4; | |
87 | + p->rank18_4 = P.rank18_4; | |
88 | + p->score18_5 = P.score18_5; | |
89 | + p->scoreDisplay18_5 = P.scoreDisplay18_5; | |
90 | + p->rank18_5 = P.rank18_5; | |
91 | + | |
92 | + p->suivant = *l; | |
93 | + *l=p; | |
94 | +} | |
95 | + | |
96 | +void suppr_tete(Liste *l) | |
97 | +{ | |
98 | + Personne* a_suppr = *l; | |
99 | + *l = (*l)->suivant; | |
100 | + free(a_suppr); | |
101 | +} | |
102 | + | |
103 | +void affiche_personne(Personne P) | |
104 | +{ | |
105 | + printf("%s %s %d %c \n", P.lastName, P.firstName, P.overallScrore, P.gender); | |
106 | +} | |
107 | + | |
108 | +void affiche_liste(Liste l) | |
109 | +{ | |
110 | + Liste tmp = l; | |
111 | + | |
112 | + if(tmp==NULL) | |
113 | + { | |
114 | + printf("Liste de personne vide\n"); | |
115 | + return; | |
116 | + } | |
117 | + | |
118 | + while(tmp != NULL) | |
119 | + { | |
120 | + affiche_personne(*tmp); | |
121 | + tmp = tmp->suivant; | |
122 | + } | |
123 | + printf("\n"); | |
124 | +} | |
125 | + | |
126 | +/************************************************************************/ | |
127 | + | |
128 | + | |
129 | + | |
130 | +void remplissage_personne(char* tab_char[], Personne *P) | |
131 | +{ | |
132 | + P->athId = atoi(tab_char[0]); | |
133 | + P->regId = atoi(tab_char[1]); | |
134 | + P->divId = atoi(tab_char[2]); | |
135 | + P->lastName = tab_char[3]; | |
136 | + P->firstName = tab_char[4]; | |
137 | + P->gender = *tab_char[5]; | |
138 | + P->age = atoi(tab_char[6]); | |
139 | + P->weight = tab_char[7]; | |
140 | + P->height = tab_char[8]; | |
141 | + P->affiliateId = atoi(tab_char[9]); | |
142 | + P->affiliateName = tab_char[10]; | |
143 | + P->overallScrore = atoi(tab_char[11]); | |
144 | + P->overallRank = atoi(tab_char[12]); | |
145 | + P->score18_1 = atoi(tab_char[13]); | |
146 | + P->scoreDisplay18_1 = tab_char[14]; | |
147 | + P->rank18_1 = atoi(tab_char[15]); | |
148 | + P->score18_2 = atoi(tab_char[16]); | |
149 | + P->scoreDisplay18_2 = tab_char[17]; | |
150 | + P->rank18_2 = atoi(tab_char[18]); | |
151 | + P->score18_2a = atoi(tab_char[19]); | |
152 | + P->scoreDisplay18_2a = tab_char[20]; | |
153 | + P->rank18_2a = atoi(tab_char[21]); | |
154 | + P->score18_3 = atoi(tab_char[22]); | |
155 | + P->scoreDisplay18_3 = tab_char[23]; | |
156 | + P->rank18_3 = atoi(tab_char[24]); | |
157 | + P->score18_4 = atoi(tab_char[25]); | |
158 | + P->scoreDisplay18_4 = tab_char[26]; | |
159 | + P->rank18_4 = atoi(tab_char[27]); | |
160 | + P->score18_5 = atoi(tab_char[28]); | |
161 | + P->scoreDisplay18_5 = tab_char[29]; | |
162 | + P->rank18_5 = atoi(tab_char[30]); | |
163 | + | |
164 | +} | |
165 | + | |
166 | + | |
167 | + | |
168 | + | |
169 | +int main(int argc, char * argv[]) | |
170 | +{ | |
171 | + Personne P; | |
172 | + Liste liste_personne = NULL; | |
173 | + | |
174 | + char* tab_char[] = {"584058","11","2","Hoffer","Melanie","F","29","130 lb","66 in","10942","CrossFit Dix Hills","90506","6989","12590000","259 reps","23254","11100195","8:45","37027","11700195","170 lb","11594","13520090","352 reps","7971","11110058","111 reps","6105","11010000","101 reps","4555"}; | |
175 | + remplissage_personne(tab_char, &P); | |
176 | + ajout_tete(&liste_personne, P); | |
177 | + | |
178 | + tab_char[3] = "Mathis"; | |
179 | + tab_char[4] = "Dupre"; | |
180 | + remplissage_personne(tab_char, &P); | |
181 | + ajout_tete(&liste_personne, P); | |
182 | + | |
183 | + affiche_liste(liste_personne); | |
184 | + | |
185 | + printf("Done\n"); | |
186 | + return 0; | |
187 | +} | |
0 | 188 | \ No newline at end of file | ... | ... |