Reputation: 5351
typedef struct A
{
short B;
short C;
} New_Type;
struct Move_Information
{
New_Type Position [25];
};
I am a newbie in C, and I don't really understand the meaning of "array in struct".
Could any wizard explain how to use it ? Thanks.
Upvotes: 0
Views: 117
Reputation: 445
It is nothing but declaring a structure which contains array of type New_type .
to use it -
Struct Move_Information new_node ;
new_node.position[x].B = "your B data ";
new_node.position[x].C = "your C data ";
Hope it clarifies your doubt .
Upvotes: 1
Reputation: 19232
Suppose you had a plain old c type in a struct:
struct Other_Information
{
int x[25];
};
You could then make one of these structs and access the data member as follows:
Other_Information info;
info.x[0] = 42;//set the first item
Similarly, for Move_Information you can index into the array, then access that structures members a so:
Move_Information info;
info.Position[0].B = 42;
Upvotes: 2
Reputation: 399703
It simply means that one member in a struct, Position
in your case, is an array. In this case it's an array of the type New_Type
, which happens to be a struct
too, but that doesn't matter.
You can access indexed elements of the array just as with any other array:
struct Move_Information moves;
moves.Position[0].B = 12;
moves.Position[0].C = 4711;
Upvotes: 2