Array as function parameter

Discussion in 'C' started by morganJohnson, Aug 28, 2010.

  1. morganJohnson

    morganJohnson New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I've got a slight problem with a function I'm writing. I'm trying to pass a 2d array to a function whose sole purpose is to display the contents of said array. Now, what I'm about to give you all compiles, but my compiler (bloodshed's dev-c++ v4.9.9.2) is giving me "warnings". I'd rather not have any warnings in this program. I'm picky like that. And yes, I am compiling into c and not c++.
    Here is the relevant code (the whole being 545 lines), any help would be much appreciated:
    #include
    #include

    const int size = 3; //global constant

    int printBoard(const int[][]); //prototype

    int main()
    {
    int board[size][size];
    //for loops for initializing array
    printBoard(board);
    return 0;
    }

    int printBoard(const int board[size][size])
    {
    //135 lines of code for displaying the array
    return 1;
    }
    any time i try to change the prototype and function to "const int**" or even "const int*[]", the program hangs for a sec, then crashes. I'm assuming it's because the pointer is accessing a restricted memory location, but that's something else entirely.
    Please note: in the code, i access the array via "board[0][1]" and such. If that is another possible problem, please let me know.
    The exact error message I get is as follows:
    "[Warning] passing arg1 of 'printBoard' from incompatible pointer type"

    help plz and thanks
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice