[問題] 讓 function 存取 array

看板C_and_CPP (C/C++)作者 (史瑞克)時間15年前 (2011/01/02 21:15), 編輯推噓0(008)
留言8則, 3人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, Gcc, Linux, ...) Linux 額外使用到的庫(Library Used) (Ex: OpenGL, ...)問題(Question): 請問如何讓 function 存取 struct array ??? 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code): (請善用置底文標色功能) #include <stdio.h> #include <stdlib.h> #include <time.h> struct Guest { int arri; int tran; int proc; int wait; int leave; }; void Random ( Guest guest[10] ); int main() { Guest guest[10]; Random ( guest[10] ); } // 補充說明(Supplement): 我就先寫到這樣 compile 看看,結果 compile 一直不能過 error: cannot convert 'Guest' to 'Guest*' for argument '1' to 'void Random(Guest*)' -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.135.27.39

01/02 21:17, , 1F
型態根本不對阿 XDD
01/02 21:17, 1F

01/02 21:18, , 2F
改成 Guest Random ( Guest guest[10] ); ???
01/02 21:18, 2F

01/02 21:18, , 3F
改成 Random ( guest ); 就可以了
01/02 21:18, 3F

01/02 21:19, , 4F
你要知道 Random ( guest ); 有沒有[10]的差別是什麼
01/02 21:19, 4F
改了之後跳出 (.text+0x51): undefined reference to 'Random(Guest*)' ※ 編輯: shrekwang 來自: 140.135.27.39 (01/02 21:24)

01/02 21:50, , 5F
加個 void Random ( Guest guest[10] ) { } 上去就好
01/02 21:50, 5F

01/02 22:16, , 6F
解決了 感謝各位大大m(_ _)m
01/02 22:16, 6F

01/03 11:44, , 7F
我是被標題吸引進來的 ~"~
01/03 11:44, 7F
※ 編輯: shrekwang 來自: 221.120.65.189 (01/03 13:22)

01/03 13:23, , 8F
Sorry 標題取的不好...
01/03 13:23, 8F
文章代碼(AID): #1D87gBS4 (C_and_CPP)
文章代碼(AID): #1D87gBS4 (C_and_CPP)