![]() |
||
|
Regular Member
![]() ![]() 加入日期: Oct 2004 您的住址: 虛擬的世界
文章: 66
|
可以幫我看看這條程式是錯什麼意思的嗎?
#include<stdio.h>
#include<stdlib.h> struct llist { int num; char na[10]; struct llist *next; }; struct llist *createllist(struct llist *head) { struct llist *head;<<<<這條錯 struct llist *ptr,*ptr1; int i; head=(struct llist *)malloc(sizeof(struct llist)); printf("輸入姓名:"); scanf("%s",ptr->na); printf("輸入編號:"); scanf("%d",ptr->num); head->next=NULL; ptr=head; for(i=1;i<5;i++) { ptr1->next=(struct llist *)malloc(sizeof(struct llist)); printf("輸入姓名:"); scanf("%s",ptr->na); printf("輸入編號:"); scanf("%d",ptr->num); ptr1->next=NULL; ptr->next=ptr1; ptr=ptr->next; } } struct llist *findnode(struct llist *head,int num) { struct llist *ptr; ptr=head; while(ptr!=NULL) { if(ptr->num==num) return ptr; ptr=ptr->next; } } void main() { struct llist *head,*ptr; int num; head=createllist(head); printf("郵寄編號:"); scanf("%d",&num); if(num!=0) { ptr=findnode(head,num); if(!ptr) printf("沒有找到\n"); else printf("姓名:%s\n",ptr->na); } } 如題囉!! 他說是Cpp1.cpp(11) : error C2082: redefinition of formal parameter 'head' 看不懂 ![]() 此文章於 2005-06-20 01:39 PM 被 jackyepson 編輯. |
|||||||
|
|
|
Advance Member
![]() ![]() 加入日期: Jun 2003 您的住址: Taipei
文章: 442
|
createllist 這個函數已經傳入一個 llist 的 pointer 名曰 head,你又在裡面宣告一個 head,自然是"參數名稱重覆定義"啦!
|
||
|
|
|
Regular Member
![]() ![]() 加入日期: Oct 2004 您的住址: 虛擬的世界
文章: 66
|
ㄜ...有點不懂!!
是要改換成這樣嗎?? struct llist *createllist(struct llist *head2) { struct llist *head; |
|
|
|
Advance Member
![]() ![]() 加入日期: Jun 2003 您的住址: Taipei
文章: 442
|
引用:
這樣子改應該可以修正你原本的得到的錯誤訊息. 有自己 compile 過一遍了嗎? |
|
|
|
|
Regular Member
![]() ![]() 加入日期: Oct 2004 您的住址: 虛擬的世界
文章: 66
|
有啊!!可是還是不行Q_Q
|
|
|
|
Advance Member
![]() ![]() 加入日期: Jun 2003 您的住址: Taipei
文章: 442
|
引用:
所謂不行,是指錯誤訊息仍然是 redefinition of formal parameter 'head' ? |
|
|
|
|
Regular Member
![]() ![]() 加入日期: Oct 2004 您的住址: 虛擬的世界
文章: 66
|
是多了警告,和一個錯
C:\Documents and Settings\123\桌面\電腦作業\Cpp1.cpp(32) : error C4716: 'createllist' : must return a value C:\Documents and Settings\123\桌面\電腦作業\Cpp1.cpp(16) : warning C4700: local variable 'ptr' used without having been initialized C:\Documents and Settings\123\桌面\電腦作業\Cpp1.cpp(23) : warning C4700: local variable 'ptr1' used without having been initialized C:\Documents and Settings\123\桌面\電腦作業\Cpp1.cpp(43) : warning C4715: 'findnode' : not all control paths return a value C:\Documents and Settings\123\桌面\電腦作業\Cpp1.cpp(48) : warning C4700: local variable 'head' used without having been initialized 此文章於 2005-06-20 03:02 PM 被 jackyepson 編輯. |
|
|
|
Advance Member
![]() ![]() 加入日期: Jun 2003 您的住址: Taipei
文章: 442
|
忽然發現我陷入了無限迴圈...
![]() 你得到"錯誤"訊息的原因:函數 createllist 在宣告時就說了要傳回一個 llist 的指標,你的函數本體中並沒有明言什麼時候傳回,和傳回什麼東西,自然得此訊息. 你得到"警告"訊息的原因:那幾個區域變數都未經初始化(給定初值)就直接拿來使用, compiler 好心提醒你該初始化它們一下. 最後,和網友這樣子一來一回地討論這種只是因為語法錯誤而得到的錯誤訊息,並不是一個良好的互動方式,建議你找身旁的朋友或老師討教,才不會浪費了網路資源,和網友的耐心。 如果你無可避免地要用這種方式討論的話,最起碼可以做到"詳述問題"這一點,而不是一個"仍然無法編譯成功"的回應,讓人不知道你的編譯器到底告訴了你什麼... 此文章於 2005-06-20 03:20 PM 被 harrisonlin 編輯. |
|
|