So I wanted to be better at pointers in C, so I try to use them in structures, functions and stuff, but in this simple example I'm having a weird problem, I think it has to do with the ordering So I respected the order as in the structure while using printf, but still it gives me 'segmentation fault' with no compiling errors, please help me !
-Here is the code :
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct
{
float *dbl;
int *age;
} Coordonnees;
int main()
{
Coordonnees joueur;
*joueur.dbl= 12;
*joueur.age= 13;
printf("dbl= %f ",*joueur.dbl);
printf("Age= %d",*joueur.age);
return 0;
}
-but Doing only this works fine and prints "dbl=12.0000" :
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct
{
float *dbl;
int *age;
} Coordonnees;
int main()
{
Coordonnees joueur;
*joueur.dbl= 12;
printf("dbl= %f ",*joueur.dbl);
return 0;
}