将多维数组传递给函数

时间:2018-11-03 15:22:57

标签: c arrays function multidimensional-array

我想知道如何将二维数组传递给另一个函数。

我当前的代码如下:

(假设n,m已经在main()中声明了。)

int new_mapping(int,int,int [],int []);

int main(int argc, char *argv[]){
    int new[n][m];
    int ori[n][m];
    new_mapping(n,m,new,ori);
}

int new_mapping(int n, int m, int new[][m], int ori[][m+1]){

}

我想将new和ori传递给new_mapping函数。但是,我收到了很多错误消息。

warning: passing argument 3 of ‘new_mapping’ from incompatible pointer type [enabled by default]

note: expected ‘int *’ but argument is of type ‘int (*)[(sizetype)(m)]’

warning: passing argument 4 of ‘new_mapping’ from incompatible pointer type [enabled by default]

note: expected ‘int *’ but argument is of type ‘int (*)[(sizetype)(m + 1)]’

At top level:
error: conflicting types for ‘new_mapping’

我定义的方式是错误的还是调用的方式,或者两者都是?非常感谢!

0 个答案:

没有答案