c - 一群人在 c 中使用结构体?

标签 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]

任何提示都会很棒!!

最佳答案

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

关于c - 一群人在 c 中使用结构体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23351453/

相关文章:

c - 在 C 或 C++ 中,我可以对哪些文件可以包含我的头文件施加限制

我们可以这样传递结构成员吗?

Javascript 和 HTML : get the first value of an array row

ruby .gsub 替换/替换特定范围的索引

c - 在 C 中将指针传递给结构体?

c++ - 如何像firefox一样保存首选项?

c - 什么样的错误将 "errno"设置为非零?为什么 fopen() 设置 "errno"而 fputc() 不设置?

string - 使用分隔符打印结构体中的字段列表

c - 返回除数之和的函数,不带余数,C

c++ - 如何初始化以结构为值的映射?