Thread: Help with two-dimensional arrays and function

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    146

    Help with two-dimensional arrays and function

    Hi,

    I want to pass a two dimensional array by reference to a function and then manipulate it's content in the called function.

    I'm not sure about how to do it.

    If you can help...

    Thanks,
    Edesign

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Even though it was posted in the C++ programming forum, in this case you can refer to this thread on 2D arrays.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    146
    Thanks laserlight.

    I followed the thread u suggested and it works, though gcc gives me warning after compilation.

    Here's how my program look like
    Code:
    int main()
    {
    int mat[3][3];
    ...
    ...
    transpose(mat);
    ...
    ...
    }
    
    void transpose(int (*mat)[3])
    {
    ...
    }
    and this is the warning I get....

    warning: conflicting types for ‘transpose’
    note: previous implicit declaration of ‘transpose’ was here
    What may be the reason?

    Thanks
    Edesign

    p.s: also how should I declare it? declaring as transpose(int *[]) gives error...

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by edesign
    What may be the reason?
    You forgot the function prototype.

    Quote Originally Posted by edesign
    p.s: also how should I declare it? declaring as transpose(int *[]) gives error...
    Copy and paste the first line of the function definition, adding a semi-colon at the end.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function and Arrays of Structures
    By Lucky Luke in forum C Programming
    Replies: 4
    Last Post: 12-14-2009, 03:19 PM
  2. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  3. Arrays as function arguments :(
    By strokebow in forum C Programming
    Replies: 10
    Last Post: 11-18-2006, 03:26 PM
  4. Arrays as function arguments!
    By strokebow in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 02:32 PM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM