我有2個結構使用指針形成一個鏈表。錯誤:請求會員'****'在某些不是結構或工會
typedef struct {
char *text;
int count;
} *Item;
typedef struct node {
Item item;
struct node *next;
} *link;
我試圖通過這種類型創建一堆操作,但我在這個特定的功能有很多問題。
error: request for member ‘text’ in something not a structure or union strcpy(new->item->text, buffer->text);
error: request for member ‘text’ in something not a structure or union new->item->text = (char*) malloc(sizeof(char)*(strlen(buffer->text)+1));
基本上是錯誤的buffer->文本通,但我一直在瞎搞與它過去一小時,似乎無法找到什麼毛病。我可能錯過了一些顯而易見的東西,但我無法包裹我的聽聞了。
link new_item(Item* buffer) {
link new = (link) malloc(sizeof(struct node));
new->item->text = (char*) malloc(sizeof(char)*(strlen(buffer->text)+1));
strcpy(new->item->text, buffer->text);
new->item->count = 1;
new->next = NULL;
return new;
}
該消息有時意味着您正在使用'.',其中應該使用' - >',反之亦然。或者,這意味着參考的LHS既不是指向結構也不是結構的指針;這就是你的問題。請參見[typedef指針](http://stackoverflow.com/questions/750178/is-it-a-good-idea-to-typedef-pointers) - 答案是「否」,因爲它會導致像這樣的問題。變量'buffer'是指向結構指針的指針;你需要使用'(* buffer) - > text'等等。或者你需要把函數改成'link new_item(Item buffer)'。 –