作者sumty (elva)
看板b96902HW
標題[鋼彈] 6-2 二維陣列跟函式的問題
時間Sat Nov 10 13:37:49 2007
/*6-2*/
void con(int*,int,int);
int main(){
int row,col,im[size][size];
......
con(im,row,col); /*第15行*/
........
}
void con(int*im,int row,int col){
if(.....){
if(im[row][col]==1){ /*第24行*/
...............
}
}
}
出現這樣的compiler waring跟error (p.s.在linux操作環境下)
b96025@linux8 [~/hw/a6] gcc a6-p2.c
a6-p2.c: In function 'main':
a6-p2.c:15: warning: passing argument 1 of 'con' from incompatible pointer
type
a6-p2.c: In function 'con':
a6-p2.c:24: error: subscripted value is neither array nor pointer
想請問大家,這是什麼意思呢?
是否是二維陣列不能以指標的方式丟到函式裡
如果是
想請教大家我要如何能將二維陣列放進函式裡處理
感激不盡
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.120.3.198
1F:推 simonxander:這我也不知道甚麼意思XD 不過有兩種方法可以解決 11/10 18:04
2F:→ simonxander:1 不要用函式就好啦~ 11/10 18:05
3F:→ simonxander:2 void con(int im[size][size]) 11/10 18:06
4F:→ simonxander:main 裡傳入 con(im) 11/10 18:07
5F:→ simonxander:這樣是傳址喔~ 喔 還有第三種 直接開全域變數 11/10 18:07
6F:→ simonxander:就不用傳了... 11/10 18:08
7F:推 Himax:果然還是只好用全域變數大絕招了 11/10 21:18
8F:推 ec75413:con(int **im) 想挑戰者 請使用指標的指標 11/10 22:17