通过二维数组在C中发挥作用? [英] Pass 2d array to function in C?

查看:145
本文介绍了通过二维数组在C中发挥作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这很简单,但我似乎无法使这项工作。

I know it's simple, but I can't seem to make this work.

我的功能是像这样:

 int GefMain(int array[][5])
 {
      //do stuff
      return 1;
 }

在我的主:

 int GefMain(int array[][5]);

 int main(void)
 {
      int array[1800][5];

      GefMain(array);

      return 0;
 }

我提到的有用的资源,但我仍然得到错误警告:从兼容的指针类型传递GefMain的参数1?我在做什么错

I referred to this helpful resource, but I am still getting the error "warning: passing argument 1 of GefMain from incompatible pointer type." What am I doing wrong?

编辑:

在code是在两个文件中,由编译器连接在一起。我不是用gcc。以上code是什么我有,除了函数声明为在主外部INT。谢谢大家的时间。

The code is in two files, linked together by the compiler. I am not using gcc. The above code is exactly what I have, except the function is declared as "extern int" in the main. Thank you all for your time.

推荐答案

在code是罚款。在一个单一的文件,该编译罚款,我与海湾合作委员会。

The code is fine. In a single file, this compiles fine for me with gcc.

int g(int arr[][5])
{
    return 1;
}

int main()
{
    int array[1800][5];
    g(array);
    return 0;
}

我的猜测是,你的#include ING错误的文件 - 或许是一个有不同的声明 GefMain 。或许你只是还没有保存的申报文件 GefMain ,所以它仍然有 INT [] [3] 举例来说,这将导致警告

My guess is that you're #includeing the wrong file -- perhaps one that had a different declaration for GefMain. Or perhaps you just haven't saved the file that declared GefMain, so it still has an argument of int [][3], for instance, which would cause the warning.

我建议您发布整个code来重现问题(你去掉一切不必要的重现它,当然后)。但机会是,在这一点上,你必须自己解决了。

I would suggest that you post the entire code to reproduce the problem (after you strip out everything that's unneeded to reproduce it, of course). But chances are, at that point, you'll have solved it yourself.

这篇关于通过二维数组在C中发挥作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆