Accès aux champs d'une structure
Bonjour, j'ai un souci avec le champ pointeur d'une structure sur une autre, j'ai deux structures dont l'une contient un pointeur vers vers, maintenant je veux accéder aux champs de la structure pointée en passant par la structure qui contient le pointeur. Vs avez ici les codes pour mieux cerner de quoi je parle.
déclaration des structure
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| struct pixel
{
unsigned short R,G,B;
}; typedef struct pixel pixel;
struct imagePPM
{
char *nombreMagique[3];
char col,lig;
short max;
pixel * pixels;
};typedef struct imagePPM imagePPM;
pixel initialise(unsigned short r, unsigned short g, unsigned b);
void initialise2(unsigned short r, unsigned short g, unsigned b, pixel *p);
imagePPM *creerImagePPM(unsigned char col, unsigned char lig, unsigned char max);
void affichePixels(imagePPM *image);
void save(imagePPM *image, char *nomFic); |
les fonctions
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| magePPM * creerImagePPM(unsigned char col, unsigned char lig, unsigned char max)
{
imagePPM *image = malloc(sizeof(imagePPM));
image->col=col;
image->lig=lig;
image->max=max;
image->nombreMagique[0]="P";
image->nombreMagique[1]="3";
return image;
}
void affichePixels(imagePPM *p)
{
printf("les codes de couleurs: %d %d %d\n",p->pixels->R,p->pixels->G,p->pixels->B);
} |
epuis dans le main j'appelle la fonction affichePixels j'ai une erreur de segmentation
Code:
1 2 3 4 5 6 7 8 9
| #include <stdio.h>
#include "tp3.h"
#include <stdlib.h>
int main(int argc, char argv[])
{
imagePPM *image;
image = creerImagePPM(2,2,5);
affichePixels(image);
} |
Je voudrais afficher les valeurs par défaut des champs p->pixels->R,p->pixels->G,p->pixels->B