www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/02/19:16:41

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: NEED HELP passing multi-dim arrays to functions
Date: Sun, 02 Feb 1997 18:04:39 -0800
Organization: Two pounds of chaos and a pinch of salt
Lines: 43
Message-ID: <32F547B7.CB5@cs.com>
References: <5d2sdh$jhj AT News DOT Dal DOT Ca>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp211.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Graham Howard Wile wrote:
> 
>         I have a problem with passing multi-dimensional arrays to my function.
> Can anyone show me how to pass multi-dimensional arrays to functions?

Try this:

#include <iostream.h>

#define MAXX 3
#define MAXY 3

void print_array(int [][MAXY]);

int main( void )   // NEVER use void main() - it's terribly bad code
        {
        int array1[MAXX][MAXY] = { { 1, 2, 3 }, { 4, 5, 6} };

        print_array(array1);
        }

void print_array(int par_array1[][MAXY])
        {
        cout << "array1[0][0]:\t" << par_array1[0][0] << endl;
        cout << "array1[0][1]:\t" << par_array1[0][1] << endl;
        cout << "array1[0][2]:\t" << par_array1[0][2] << endl;

        cout << "array1[1][0]:\t" << par_array1[1][0] << endl;
        cout << "array1[1][1]:\t" << par_array1[1][1] << endl;
        cout << "array1[1][2]:\t" << par_array1[1][2] << endl;
        }

That should work the way you want it to.  If you have any problems,
email me, because I'm not in a position to test it right now.  :)

l8r

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I  |        fighteer AT cs DOT com         |
| Plan:  To find ANYONE willing to |   http://www.cs.com/fighteer   |
| play Descent 2 on DWANGO!        | Tagline: <this space for rent> |
---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019