pointeur de structure en parametre d'une fonction :s
hello tlm
alors voilà mon soucis, j'ai un pointeur sur une structure. et je voudrais passé celle-ci en paramètre de 2 fonctions, une pour l'affichage de ma struct, et l'autre pour l'initialisation.
ayant toujours des problemes lorsqu'il sagit de passage en paramètre avec des pointeurs je me suis renseigner avant mais a la compilation j'ai un warning, et à l'exécution j'ai une erreur de segmentation..
qq pourrait-il regarder mon code et me dire mon probleme?
merci bcp
Code:
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
|
struct repart_struct{
int repartTab[4][4];
};
struct nombre_de{
int reader;
int joueur;
};
main(){
struct repart_struct* repartition;
struct nombre_de* nombre_de;
init(&repartition);
printf("%d\n",repartition->repartTab[0][0]);
afficheRepartition(&repartition);
}
void afficheRepartition(struct repart_struct* repartition){
int i,j;
for(i=0;i<4;i++){
for(j=0;j<4;j++){
switch(j){
case 0 : printf("Nb de joueur : ");break;
case 1 : printf("Nb de pion de chaque joueur : ");break;
case 2 : printf("Nb de pion caché : ");break;
case 3 : printf("Nb de pion visible : ");break;
}
printf("%d ",repartition->repartTab[i][j]);
}
printf("\n");
}
}
void init(struct repart_struct* repartition){
repartition->repartTab[0][0]= 2;
repartition->repartTab[0][1]= 7;
repartition->repartTab[0][2]= 7;
repartition->repartTab[0][3]= 7;
repartition->repartTab[1][0]= 3;
repartition->repartTab[1][1]= 7;
repartition->repartTab[1][2]= 7;
repartition->repartTab[1][3]= 0;
repartition->repartTab[2][0]= 4;
repartition->repartTab[2][1]= 5;
repartition->repartTab[2][2]= 4;
repartition->repartTab[2][3]= 4;
repartition->repartTab[3][0]= 5;
repartition->repartTab[3][1]= 4;
repartition->repartTab[3][2]= 4;
repartition->repartTab[3][3]= 4;
} |
mes waring :
Code:
1 2 3 4 5
|
serveur.c:72: attention : conflicting types for afficheRepartition
serveur.c:70: attention : previous implicit declaration of afficheRepartition was here
serveur.c:87: attention : conflicting types for init
serveur.c:68: attention : previous implicit declaration of init was here |
et à l'execution ca plante au moment de l'appel a la fonction init(...)
Code:
1 2
|
Erreur de segmentation |
[/quote]
Re: pointeur de structure en parametre d'une fonction :s
Citation:
Envoyé par breezer911
Code:
1 2 3 4 5 6 7 8 9 10
|
main(){
struct repart_struct* repartition;
<d'apres ton autre post, 'repartition' est mis a jour. ...>
afficheRepartition(&repartition);
}
<...>
void afficheRepartition(struct repart_struct* repartition){ |
Pourquoi faire ce '&' ? Retire le.