看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) DEV C++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 一直出現[Warning]passing argument 1 of 'fnuctionName'from incompatible pointer type [enabled by default] [NOTE]expected 'int(*)[30]' but argument is of type 'int **' 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) int *index[30]; for(i=0;i<someNumber;i++) index[i] = (int*)malloc(arrLen*sizeof(int)); ... ... ... sort2DArray(index, someNumber, arrLen); .... void sort2DArray(int (*array)[30], int someNumber, int arrLen) { .... } 補充說明(Supplement): 我想建一個行列可自訂的ARRAY(一個上限為30)然後排序,但怎麼樣都不行 不知哪裡有錯,也不知怎麼改... -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.170.213.8 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1417104808.A.2FE.html
putumaxally: int (*array)[30] 改成 int **array 看看 11/28 00:20
KoenigseggG: int **? 是說不能執行嗎?warning不是? 11/28 00:22
PoorLoser: (*array)[30] ---> *array[30] 11/28 00:25
future314: 喔喔喔 感謝樓上的方法 11/28 00:27
future314: 但一般的2D陣列傳值那樣寫可以 但為什麼現在不行? 11/28 00:28
PoorLoser: 你宣告的參數叫做 pointer to array[] 11/28 00:31
PoorLoser: 你要傳進去的叫做 array[] of pointer to int 11/28 00:32
PoorLoser: someNumber 最好加 guard clause 避免超出陣列邊界 11/28 00:33
future314: 感謝講解 m(__ __)m 11/28 00:41