bil*_*ial 0 c size malloc struct structure
我有一个结构:
typedef struct {
char fname[100], lname[100];
int age, salary;
} *employer;
Run Code Online (Sandbox Code Playgroud)
而现在,我想要一个指针变量empl1,它包含足够的空间供100名员工使用:
employer empl1 = malloc(100 * sizeof(employer));
Run Code Online (Sandbox Code Playgroud)
问题是sizeof(雇主)是4 (我的机器上指针的大小).我如何获得所有雇主结构的规模?(在我的情况下是208).
你有一个无效(无法维持)的使用typedef struct
,s/b typedef struct ... employer;
(没有星号/指针)
我还建议您这样做:
typedef struct {
char fname[100];
char lname[100];
int age;
int salary;
} employer;
Run Code Online (Sandbox Code Playgroud)