remplissage d'une structure
Bonjours,
voici un bout du contenu de mat.h:
Code:
1 2 3 4 5 6 7 8
| typedef struct mat_t { // class matrice
unsigned int height;
unsigned int width;
unsigned int level; // niveau de gris max de l'image
char ** pixels; // tableau de pixels accessible avec pixels[i][j]
} mat_pas_pointeur, * mat;
mat mat_new(unsigned int width, unsigned int height);// retourne une matrice non initialisee |
puis un bout dans mat.c:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| mat mat_new(unsigned int width, unsigned int height){
// s'appelle avec la syntaxe self->pixels[ligne][colone]
mat m;
unsigned int i;
printf("juste avant l'assignation\n");
m->height = height;
m->width = width;
printf("juste avant l'allocation!\n");
m->pixels[0] = calloc(height * width, sizeof(**(m->pixels)));
printf("juste apres la premiere allocation\n");
m->pixels = calloc(height, sizeof(*(m->pixels)));
for (i=1; i<mat_height(m); i++){
m->pixels[i] = m->pixels[i-1] + mat_width(m);
}
return m;
} |
un bout du main.c:
Code:
1 2 3 4 5 6 7 8 9 10
| int main(int argc, char const *argv[]){
const char *input = NULL, *output = NULL;
const char *op = NULL;
int interp = -1;
double parm = 0.0;
mat in = NULL, out = NULL;
mat_print(mat_pgm_read("/home/dieu/Documents/Dropbox/projet_info/images/palmier.pgm")); return EXIT_SUCCESS; // pour tester pgm |
Et l'orsque le code arrive sur m->height = height; dans mat.c, il y a Segmentation fault (core dumped)
Comment puis-je faire pour avoir le droit d'accéder au champ m->height ?