gpt4 book ai didi

c - 如何将结构体的预设数组放置在不同的结构体中?

转载 作者:行者123 更新时间:2023-11-30 15:58:03 26 4
gpt4 key购买 nike

我正在经历一些用 C 语言应该很简单的事情,但由于某种原因似乎无法让它工作。

以下是结构:

    #define MAX_BRANCH 500
#define MAX_BANK_CLIENTS 100000
#define MAX_CLIENTS 10000


typedef struct Client{
char *pName;
char *fName;
int id;
int branch;
int AccountNum;
int credit;
double surplus;
double IOU;
double savings;
}Client;

typedef struct Branch{
int BrnachNum;
char *Name;
int Accounts;
double sumOfAll;
double profit;
int ActiveLoans;
int Opened;
int Closed;
Client ClientList[MAX_CLIENTS];
}Branch;

typedef struct Bank{
char *Name;
int Branches;
int Accounts;
int ActiveLoans;
double sumOfAll;
double Profit;
Branch BranchList[MAX_BRANCH];
}Bank;




int main()
{
Bank Discount;
Discount.BranchList[0].Accounts = 1;

return 0;
}

//--------------------------------------------------------

将整数值简单地放置到整数参数中显示了堆栈溢出或对内部字段的任何其他访问并且 char 指针将由 strdup 分配(我可以使用的唯一内存分配)。

请记住,我不能使用任何类型的内存分配。

第二,有人指示我设置该结构的静态数组。类似的东西

static Branch BranchList[500]

但是我怎样才能对每个分支做同样的事情呢?

最佳答案

问题似乎是您在声明结构之前就使用了它们。您可能想以相反的顺序定义它们。

关于c - 如何将结构体的预设数组放置在不同的结构体中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10070064/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com