2012-10-20 123 views
0

..然后将其指向数组或沿着这些行。我对我应该做的事感到困惑。将指向结构的指针的值获取到指向结构的另一个指针

这里有结构:

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 
    } 
    } 
} 

怎么样?

+0

我假设,因为你问你的当前行不起作用。你有任何错误构建? – Xyon

+0

@Xyon Yup,但它是一个“无效类型的参数” - >'“错误 - 我只是对符号感到困惑。 – idlackage

回答

1

你几乎在那里。 personInfo是一个指针,所以你应该把它看作:

​​
+0

我收到错误“' - >'”的无效类型参数。 – idlackage

+0

我想删除我之前对错误的评论,但无法管理它 - 但是,谢谢,这确实起作用,我只是在阅读时意外地将 - >放在其他地方。 – idlackage

+0

没关系。我很高兴它适合你。 – MByD