Bonjour,

Voilà plusieurs jours que je me tire les cheveux. Malgré plusieurs essais avec des IDE différents sur des plateformes différentes (Linux/W7 en 32/64 bits), j'ai un tableau d'enregistrements (ou de structure : tout dépens du langage que l'on utilise pour s'exprimer ) au comportement étrange. Son nom est sAnimal. Il contient divers champs. J'ai créé un tableau du type de cette structure. Ce tableau nommé "animaux" réinitialise les champs "l" et "identifiant" à zéro du premier élément du tableau (animaux[0].l et animaux[0].identifiant) dans le sous-programme tour_de_jeu sans que je lui demande...

Plutôt que de faire un grand discours, je vous présente des bouts de codes incriminés avec les "printf" qui affichent les champs se réinitialiser en commentaire dans le code.
Merci d'avance

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 
#define L_ANIMAL 20
#define L_CARTE 50
#define C_CARTE 50
 
struct animal
{
    int identifiant;//animal : de 1 à 20
    int l;
    int c; // x:ligne, y:colonne
    int boire;//boire : 3 jours max pour boire
    int manger; //manger : 10 jours max pour manger
};
typedef struct animal sAnimal;
 
...
 
void conception_tab_animal(int plateau[L_CARTE][C_CARTE],sAnimal animaux[L_ANIMAL],int nb_animal,int l_carte,int c_carte)
{
    int i,l,c;
    int identifiant_anim=IDENTIFIANT_ANIMAL; //identifiant animal : de 1 à 20
    int boire=QUANTITE_INI_ANIMAL_BOIRE;
    int manger=QUANTITE_INI_ANIMAL_MANGER;
 
    for(i=0; i<nb_animal; i++)
    {
        animaux[i].identifiant= identifiant_anim;
        animaux[i].boire= boire;
        animaux[i].manger=manger;
        do
        {
            l=calc_coord_l(l_carte);
            c=calc_coord_c(c_carte);
	printf("l=calc_coord_l=%d, c=calc_coord_c=%d",l,c); // coordonnees variant de 0 à 19
       getchar();
        }
        while(plateau[l][c]!=0);
 
        animaux[i].l=l;
        animaux[i].c=c;
 
        printf("\ni=%d \t conception tab animalidentifiant animal = %d, l=%d, c=%d ",i,animaux[i].identifiant,animaux[i].l,animaux[i].c); // tous les champs sont bon
 
         getchar();
        plateau[l][c]=identifiant_anim;
 
        identifiant_anim++;
    }
    return;
 
}
 
void tour_de_jeu(int plateau[L_CARTE][C_CARTE], int l_carte, int c_carte, sAnimal animaux[L_ANIMAL], int *nb_animal, sEau tab_eau[L_EAU], int *nb_eo, sHerbe tab_herbe[L_HERBE], int *nb_herb, int id_zero_tab_animaux, int l_tab_animaux, int id_tab_eau)
{
//renvoi 0:rien, 1:animal, 2:eau, 3:herbe 10:depassement tableau
 
    int i,j,id_case;
    int deplacement_oui_ou_non;//0:impossible 1:possible
    int direction;
    int nb_deplacement;
    int position_dans_tab_animaux;
    int nb_tentative_changement_direction=0;
 
   printf("\ntour de jeu dentifiant=%d animaux[0].l=%d animaux[0].c=%d\n",animaux[0].identifiant,animaux[0].l,animaux[0].c); // LA LES CHAMPS animaux[0].l et animaux[0].identifiant sont à ZERO alors que animaux[0].c est bon ?!!
...
 
 
 
int main()
{
    sAnimal animaux[L_ANIMAL];
 
...
    conception_tab_animal(plateau,animaux,nb_animal,l_carte,c_carte);
 
    for(i=0; i<nb_animal; i++)
    {
 
           printf("\nMAIN %d eme animal - identifiant=%d , l= %d, c=%d ",i,animaux[i].identifiant,animaux[i].l,animaux[i].c); // // tous les champs sont bon
         getchar(); //pour faire une pause
  }
....
  for(i=0; i<duree; i++)
    {
 
        affiche_plateau(plateau,l_carte,c_carte);
        printf("\nTOUR numero = %d ",i+1);
 
        tour_de_jeu(plateau,l_carte,c_carte,animaux,&nb_animal,tab_eau,&nb_eo,tab_herbe,&nb_herb,id_zero_tab_animaux,l_tab_animaux,id_tab_eau); //appel au s/prog tour_de_jeu et PAF dans ce s/prog LES CHAMPS animaux[0].l et animaux[0].identifiant sont à ZERO !!!
 
}
...