一群人在c中使用结构?

时间:2014-04-28 21:25:13

标签: c arrays struct

我需要创建一个人的数组,同时使用这样的结构: -

typedef struct Person

{
     int age;      //needs to be randomly generated
     int height;   //needs to be randomly generated
     int weight;   //needs to be randomly generated
} Person;

但我不知道如何使用如下数组执行此操作: -

人[0]

人[1]

人[2]

任何提示都会很棒!!

1 个答案:

答案 0 :(得分:0)

typedef struct Person
{
     int age;      //needs to be randomly generated
     int height;   //needs to be randomly generated
     int weight;   //needs to be randomly generated
} Person;

// Create an array of 5 Persons
Person persons[5];

// Set the data of the first person.
person[0].age = 25;
person[0].height = 175; // in cm
person[0].weight = 68; // in kg