[問題] assignment from incompatible pointer

看板C_and_CPP (C/C++)作者 (自我催眠)時間14年前 (2011/10/15 22:44), 編輯推噓0(005)
留言5則, 2人參與, 最新討論串1/1
開發平台(Platform): dev c++ 問題(Question): 小弟嘗試利用linked list的方法寫stack但是編譯後出現 "warning: assignment from incompatible pointer type" 以下是部分程式碼 //宣告結點 struct n{ int data; struct node *next; }; //宣告top struct n *top = NULL; //push void push(int in) { struct n *tmp; tmp = (struct n *)malloc(sizeof(struct n)); tmp->data=in; tmp->next=top; top=tmp; } 警告出現在 tmp->next=top這行 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.33.236.246

10/15 22:45, , 1F
你的strct node呢?
10/15 22:45, 1F

10/15 22:48, , 2F
不能用n取代node嗎 還是一定要打struct node{}
10/15 22:48, 2F

10/15 22:55, , 3F
你沒定義struct node是什麼 就不能用它
10/15 22:55, 3F

10/15 22:56, , 4F
你把struct node *next變成struct n *next就好了
10/15 22:56, 4F

10/15 22:57, , 5F
感謝!!!!!
10/15 22:57, 5F
文章代碼(AID): #1EcPmwN8 (C_and_CPP)
文章代碼(AID): #1EcPmwN8 (C_and_CPP)