
Initialising Structure Within Structure...How?!
Hi,
As the title says, how can you initialise structure within another
structure without defining the size of the second structure (inner)?
For example, consider the following code:
/* Example Of Initialising Structure Inside Structure */
#include <stdio.h>
struct Location {
struct Position {
int X;
int Y;
} Point[2]; /* If you don't define the size, you'll get an error */
int Z;
Quote:
};
/* Here Iam trying to initialise the structure (POS) */
struct Location Pos = { {{2,5}, {10,90}} , 0};
void main()
{
Pos.Z = Pos.Point[0].X + Pos.Point[0].Y;
printf("\nZ = %d\n", Pos.Z);
Pos.Z = Pos.Point[1].X + Pos.Point[1].Y;
printf("Z = %d\n", Pos.Z);
Quote:
}
This programme will run as long as you define the size of the structure
of (POSITION) which called (POINT). But if you don't define the size,
which I would (strongly) like to do here, you'll get this error:
Error...: Size of the type is unknown or zero
Do you know what's wrong with my code and how can I get around this
problem please?
Your help appreciated, and thanx in advance...
__ _________________________________
/ || Hashem Al-Dhaheri
/____|| ____ ___ ___ ___
/ || - / //__//__//__//__ /___) /
/ ||___ /___// // // //__ / \ /