I have this code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct vector_{
int x;
double y;
double z;
} *vector;
void modi(vector a);
int main() {
vector var;
var->x = 2;
modi(var);
return 0;
}
void modi(vector a){
printf("avant modif %d",a->x);
a->x = 5;
printf("avant modif %d",a->x);
}
I tried to run it but I got a segmentation fault.
The problem is simple: the access/modify with a struct pointer variable.
I look on Stack Overflow but I got an incomplete answer for my problem: https://stackoverflow.com/a/1544134
What is the right way to access/modify in this case (a struct
pointer variable)?