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

From: an118 AT chebucto DOT ns DOT ca (Graham Howard Wile)
Newsgroups: comp.os.msdos.djgpp
Subject: NEED HELP passing multi-dim arrays to functions
Date: 2 Feb 1997 20:11:29 GMT
Organization: Chebucto Community Net
Lines: 62
Message-ID: <5d2sdh$jhj@News.Dal.Ca>
NNTP-Posting-Host: chebucto.ns.ca
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

	I have a problem with passing multi-dimensional arrays to my function. 
Can anyone show me how to pass multi-dimensional arrays to functions?

	The following code always works fine for a single dimensional array, 
but not multi-dim's like the one in the example below (also, see my compiler 
output below that):



#include <iostream.h>

void print_array(int *);

void main()
	{
	int array1[3][3];


	array1[0][0] = 1;
	array1[0][1] = 2;
	array1[0][2] = 3;

	array1[1][0] = 4;
	array1[1][1] = 5;
	array1[1][2] = 6;

	print_array(array1);
	}


void print_array(int * par_array1)
	{
	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;
	}



Here's what I get for my compiler errors:

c:\c_progra.ms>gxx testing.cc -o testing.exe
testing.cc: In function `int main(...)':
testing.cc:19: passing `int (*)[3]' as argument 1 of `print array(int *)'
testing.cc: In function `void print_array(int *)':


This one it gives for lines 26-28, 30-32...

testing.cc:26: invalid types `int[int]' for array subscript


						Thanks,
							Graham


--

- Raw text -


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