Thread: double array into function

  1. #1
    C
    Guest

    Question double array into function

    int input (int *cox, int *coy, int *board[3][3]); /*declare fun*/
    input(&cox, &coy, &board); /*call func*/
    int input (int *cox, int *coy, int *board[3][3]); /*header*/

    I am trying to pass a 2d array into a function. I have follwed all the instructions but it still wont work. above are my calls. This is the error that I get:

    "lab12_3.c", line 22.22: 1506-280 (E) Function argument assignment between types "int*(*)[3]" and "int(*)[3][3]" is not allowed.

    Can someone please help me. I am completely stuck

    (6)

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    53
    You can't use the whole array as a pointer - a pointer can point at only one memory location. You want to do something like this i believe :

    Code:
    #include <stdio.h>
    
    void myfunc(int *myp);
    
    int main(void) {
       
       int myarray[5][5];
      
       myarray[0][0]=999;
       myarray[0][1]=223;
       myarray[0][2]=534;
    
       // Pass a pointer to the first position in your 2d array
       myfunc(&myarray[0][0]);      
    
       return 1;
    
    }
    
    void myfunc(int *myp) {
    
    // display the integer at that location and 
    // at an integer's worth of memory after that etc.
    
       printf("%d %d %d",*myp, *(myp+1), *(myp+2));
    }
    Does this help?

    Almosthere
    "Technology has merely provided us with a more efficient means for going backwards" - Aldous Huxley

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    53
    Sorry. .. in C++ mode

    s/\/\/(.*)$/\/\*$1\*\//g;

    "Technology has merely provided us with a more efficient means for going backwards" - Aldous Huxley

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Conversion From C++ To C
    By dicon in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 02:54 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM