[問題] C語言除錯求助

看板C_and_CPP (C/C++)作者 (咩滴可)時間11年前 (2014/12/20 16:28), 編輯推噓1(108)
留言9則, 7人參與, 最新討論串1/2 (看更多)
題目是輸入一個二維陣列 然後找出最大值的行列 compaler過關了 但是一執行就會擋掉 #include <stdio.h> #include <stdlib.h> int row; int column; void locateLargest(double a[row][column]); int main() { int i,j; double array[i][j]; scanf("%d",&row); scanf("%d",&column); for(i=0;i<row;i++) { for(j=0;j<column;j++) { scanf("%f",array[ i ][ j ]); } } locateLargest(array); } void locateLargest(double a[row][column]) { double max=0; int i,j,x,y; for(i=0;i<row;i++) { for(j=0;j<column;j++) { if(a[i][j]>max) { max=a[i][j]; x=i; y=j; } } } printf("%d%d",x,y); } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.162.252.128 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1419064131.A.C73.html

12/20 16:48, , 1F
沒看過這樣使用二維陣列的,找本C語言的書好好K一K!
12/20 16:48, 1F

12/20 16:52, , 2F
1)i,j未給值就用來宣告陣列
12/20 16:52, 2F

12/20 16:52, , 3F
2)scanf("%f",array[ i ][ j ]); 要加上&
12/20 16:52, 3F

12/21 08:50, , 4F
不能用變數宣告靜態陣列大小, 這種我編譯都不會過耶
12/21 08:50, 4F

12/21 08:51, , 5F
你想要runtime才決定陣列大小,應該用動態記憶體配置
12/21 08:51, 5F

12/21 09:18, , 6F
樓上:C99 variable-length arrays
12/21 09:18, 6F

12/21 15:55, , 7F
ptr calloc/malloc
12/21 15:55, 7F

12/24 00:43, , 8F
屁啦~這樣編譯最好會過
12/24 00:43, 8F

01/06 13:26, , 9F
C99能過吧
01/06 13:26, 9F
文章代碼(AID): #1KbJD3np (C_and_CPP)
文章代碼(AID): #1KbJD3np (C_and_CPP)