PASSINAG A bidimansional array at a function

This is a discussion on PASSINAG A bidimansional array at a function within the C++ Programming forums, part of the General Programming Boards category; how do I pass as referance a bidimansional array ata function? this int a[1][2]; void f(int **b); doesnt work ! ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    29

    PASSINAG A bidimansional array at a function

    how do I pass as referance a bidimansional array ata function?

    this
    int a[1][2];
    void f(int **b);
    doesnt work ! type mismatch.

    -i found this way ...
    struct c
    {
    int *p[2];
    } array;

    voit initNewType()
    {
    array.p[0] = &(a[0][0]);
    array.p[1] = &(a[0][1]);
    }

    void f(c *value)
    { //how do i move the array index thru the bidimansioal array?????
    *((*value).p[i]+j); //value at a[j][i]....but there 's a mistake someone can help me?
    //there's a simpler solution instead that using this mess?

    }
    main()
    { f(&array);
    }

    ///there's a esyer way to pass by referance a duble array?


    if you emailme to bruno.marovelli@fastwebnet.it i'll really apprciate it!

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Please don't cross-post. It's considered extremely rude.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is a pointer to a 2-dimentional array.

    void f(int ***data)
    {}

    Kuphryn

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >void f(int ***data)
    That's not a pointer to a two dimensional array. It's a pointer to a pointer to a pointer which would likely constitute a pointer to a dynamically simulated two dimensional array. But the question was about arrays, not pointers.
    My best code is written with the delete key.

  5. #5
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    Posts
    244
    If you are going to change the arrays content, then you do not need to pass it by reference
    Code:
    void f(int arr[4][4]);
    
    int main(){
       int myArray[4][4];
       f(myArray);
       return 0;
    }
    But if you are going to allocate it dinamically, within the function for example, then you must pass int***.
    Nothing more to tell about me...
    Happy day =)

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    closed
    replies -> PASSINAG A bidimansional array at a function
    and some bad rep to-boot just for your troubles
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 05:23 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  3. Passing my array to function
    By pooty tang in forum C Programming
    Replies: 8
    Last Post: 09-15-2004, 01:19 PM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 01:04 PM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 11:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21