..然后到一个数组,或沿着这些线。我对应该做什么感到很困惑。
这是结构:
typedef struct {
char name[30];
} PersonType;
typedef struct {
PersonType *personInfo;
} StudentType;
typedef struct {
StudentType students[30];
} GraduateType;
我想获取PersonType的名称。在main()中是这样的:
GraduateType *gptr = (GraduateType *) calloc(3, sizeof(GraduateType));
// Assume here that info has been scanf()'d
int i, j;
for(i = 0; i < 3; i++) {
for(j = 0; j < 2; j++) {
if(strcmp(gptr[i].students[j].personInfo.name, "asd")) { // <- This
// blah
}
}
}
怎么样?
最佳答案
你快到了personInfo
是一个指针,因此您应该这样对待它:
gptr[i].students[j].personInfo->name
关于c - 获取指向一个结构的指针的值到指向另一个结构的指针,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12992561/