I want to create a new structure that is the combination of two identical structures. Each of these sub structures includes one scalar double and a three dimensional array. However, when I try to initialize the structure I am getting errors when attempting to give the array its values.
I don't have compilation errors, but when I try to look into the values of the array within the nested structure, I see very completely wrong insane numbers.
Do you know what I am doing wrong here?
typedef struct quackStruct {
double s;
double v[3];
} quackStruct;
typedef struct dualquackStruct {
quackStruct q1;
quackStruct q2;
} dualquackStruct;
int main() {
quackStruct duck1 = { .s = 0.0, .v = { 0.5,4.0,2.1 } };
quackStruct duck2 = { .s = 0.85, .v = { 20.0, 10.0, -5.0 } };
/* I tried this... but it didn't work
dualquackStruct ducks = { duck1, duck2 }; */
/* this didn't work either */
dualquackStruct ducks = { .q1.s = 0.0, .q1.v = { 0.5, 4.0, 2.1 },
.q2.s = 0.85, .q2.v = { 20.0, 10.0, -5.0 } };
printf("%f\n", ducks.q1.s);
printf("%f\n", ducks.q1.v[0]);
printf("%f\n", ducks.q1.v[1]);
printf("%f\n", ducks.q1.v[2]);
printf("%f\n", ducks.q2.s);
printf("%f\n", ducks.q2.v[0]);
printf("%f\n", ducks.q2.v[1]);
printf("%f\n", ducks.q2.v[2]);
return 0;
}