bonjour,
Pour l'instant j' ai cette structure et cette initialisation qui marchent bien.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 typedef struct { char callsign[8]; char actype[5]; char departure[5]; char arrival[5]; double rfl; double pfl; double xfl; double afl; double cfl; s_waypoint *route; } s_plane; s_plane *fleet[30]; typedef struct { char wp_nom[6]; double wp_x; double wp_y; GooCanvasItem *wp_cercle; GooCanvasItem *wp_label; } s_waypoint; s_waypoint *waypoints;Puis dans le main :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 void plane_constructor(s_plane *plane, int nb_fixes, ...) { (*plane).route = malloc(nb_fixes*sizeof(*(*plane).route)); int i=0, j=0; va_list ap; va_start(ap, nb_fixes); for( i=0 ; i<nb_fixes ; i++) { strcpy((*plane).route[i].wp_nom, va_arg(ap, char *)); for (j=0; j<nb_wp; j++) { if (strcmp((*plane).route[i].wp_nom, waypoints[j].wp_nom) == 0) { (*plane).route[i].wp_x = waypoints[j].wp_x; (*plane).route[i].wp_y = waypoints[j].wp_y; (*plane).route[i].wp_cercle = NULL; (*plane).route[i].wp_label = NULL; break; } } } va_end(ap); }
Maintenant je voudrais tout initialiser en une ligne et j'avais prévu le code suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 s_plane avion1 = { "SWR422", "B777", "LSGG", "SKBO", 360.0, 360.0, 360.0, 360.0, 360.0}; plane_constructor(&avion1, 5, "MTL2", "MTL", "GRENA", "LTP", "RAPID"); fleet[0] = &avion1;
et le constructeur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part plane_constructor(fleet[0], "SWR422", "B777", "LSGG", "SKBO", 360.0, 360.0, 360.0, 360.0, 360.0, 5, "MTL2", "MTL", "GRENA", "LTP", "RAPID");
Pas de pb à la compil mais j'ai un plantage à l'éxécution du plane_constructor dès la première ligne.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 void plane_constructor(s_plane *plane, char callsign[8], char actype[5], char departure[5], char arrival[5], double rfl, double pfl, double xfl, double afl, double cfl, int nb_fixes, ...) { strcpy(plane->callsign, callsign); strcpy(plane->actype, actype); strcpy(plane->departure, departure); strcpy(plane->arrival, arrival); plane->rfl = rfl; plane->pfl = pfl; plane->xfl = xfl; plane->afl = afl; plane->cfl = cfl; (*plane).route = malloc(nb_fixes*sizeof(*(*plane).route)); int i=0, j=0; va_list ap; va_start(ap, nb_fixes); for( i=0 ; i<nb_fixes ; i++) { strcpy((*plane).route[i].wp_nom, va_arg(ap, char *)); for (j=0; j<nb_wp; j++) { if (strcmp((*plane).route[i].wp_nom, waypoints[j].wp_nom) == 0) { (*plane).route[i].wp_x = waypoints[j].wp_x; (*plane).route[i].wp_y = waypoints[j].wp_y; (*plane).route[i].wp_cercle = NULL; (*plane).route[i].wp_label = NULL; break; } } } va_end(ap); }
une idée ?
Partager