I keep getting compiler errors telling me its not a pointer as shown below.
I don't know what I am doing wrong here. I got this solution on stack overflow on another post.
typedef struct Data{
int x;
int y;
}Data;
int main (void){
Data * arrData = malloc (sizeof * arrData *6);
for (int i =0; i<6;i++){
arrData[i] = NULL;
}
for (int i =0; i < 6; i++){
printf("This is an iteration.\n");
arrData[i] = malloc (sizeof * arrData[i]);
int tempx;
int tempy;
printf("Add x and y\n");
scanf ("%d %d",&tempx,&tempy);
arrData[i] -> x = tempx;
arrData[i] -> y = tempy;
}
for (int i =0; i<6; i++){
printf("x: %d y: %d\n",arrData[i]->x,arrData[i]->y);
}
free (arrData);
return 0;
}
arrData[i]
isn't pointer.*
or->
on it or assign a pointer to it.