2012-10-20 42 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