..然后到一个数组,或者沿着这些线。我很困惑我应该做什么。
以下是结构:
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/