I'm going through something that should be simple in C but for some reason cant seem to get it to work.
Here are the structs:
#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;
}
//--------------------------------------------
this simple placement of an integer value to an integer argument shows me a stack overflow or any other accesses to the inner fields and the char pointer will be assigned by strdup(the only memory allocation i can use).
And just keep in mind that I cant use memory allocation of any kind.
Second is, some one instructed me to set a static array of the struct. Something like
static Branch BranchList[500]
but how can I do the same for each of the branches?
The problem seems to be that you're using structs before they've been declared. You might want to define them in the reverse order.