0
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.

1
  • 2
    Uhm, what's so strange about it? It's just an array that is a member of a struct, what is unclear to you? Commented Nov 26, 2013 at 13:18

3 Answers 3

2

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;
Sign up to request clarification or add additional context in comments.

Comments

2

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;

Comments

1

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 .

1 Comment

semi-colons are for wimps?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.