-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtruc.c
48 lines (45 loc) · 956 Bytes
/
truc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <stdlib.h>
#include "truc.h"
#include "coord.h"
// OK
Un_truc *creer_truc(Une_coord coord, Ttype type, Tdata data, double uv)
{
Un_truc *truc = (Un_truc*)malloc(sizeof(Un_truc));
if(truc==NULL)
{
printf("Erreur d'allocation mémoire");
return NULL;
}
truc-> coord = coord;
truc-> type = type;
truc-> data = data;
truc-> user_val = (float)uv;
return truc;
}
// OK
void detruire_truc(Un_truc *truc)
{
if (truc == NULL) return;
int i;
if((truc->type) == STA) //Si c'est une station
{
free(truc->data.sta.nom);
if (truc->data.sta.con_pcc != NULL)
{
free(truc->data.sta.con_pcc);
}
if(truc->data.sta.Tab_con !=NULL)
{
for(i=0; i < (truc->data.sta.nb_con); i++) {
free(truc->data.sta.Tab_con[i]);
}
free(truc->data.sta.Tab_con);
}
free(truc); //On désalloue la station
}
else //Si c'est une connexion
{
free(truc); //On désalloue la connexion
}
}