I'm trying to learn about nested structures and pointers in C. I made this as a test:
typedef struct xyz xyz_t;
struct xyz{
int x, y, z;
};
xyz_t array[] = {
{.x = 14, .y = 16, .z = 18},
{.x = 34, .y = 36, .z = 38},
{.x = 64, .y = 66, .z = 68},
};
typedef struct blue blue_t;
struct blue
{
int *pointer;
};
int main()
{
blue_t red;
red.pointer = &array;
printf("%d",red.pointer[1].z);
}
The idea is to have the structure red
have a pointer pointing to array
, and then print f.ex. array[1].z
.
What am I doing wrong? The compiler is telling me:
assignment from incompatible pointer type
[-Wincompatible-pointer-types]
red.pointer = &array;
request for member
x
in something not a structure or unionprintf("%d",red.pointer[2].x);