I'm hiding a pointer with the typedef and I'm trying to make an array of it. my structure is:
typedef struct s {
int y;
int x;
int value;
} s;
typedef s *t;
and the main:
int main()
{
t *var;
int arg;
var = malloc(sizeof(t*));
arg = 40;
for (int x = 0; x < arg; x++)
{
var[x] = malloc(sizeof(t));
var[x]->x = -1;
var[x]->y = -1;
var[x]->value = 0;
}
for (int x = 0; x < arg; x++)
{
printf("|%d| ",var[x]->value);
}
return 0;
}
sometime it just goes to segmentation fault and sometimes the value is just dirty, but it still means that it did not allocated the memory as intented. what am I missing? I'm just trying to make an array of type t with arg length which must be a variable