passing a 2 dimensional array to and from a function

I am trying to pass a 2 dimensional array of Stacks to a function. I created the class Stack and the code is as follows:
1
2
3
4
5
6
7
8
9
10
11
12
class Stack
{
public:
	int holder [size];//holds the values 1:9
	int knownValue;//if the value of this cell is known
	bool isEmpty()//check to see if anything is stored in holder
	{
		if (holder[0] == 0)
			return true;
		else return false;
	}
};

This class is going to be used in a program that will solve sudoku puzzles.
I have created a 9x9 two dimensional array to hold these containers.
This array was created and initialized with an input through std::cin code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
	Stack puzzle[size][size];//creates the array
	int count1 = 0; 
	int count2 = 0;
	char inputHolder[82];//holds the line of input to be inserted into the array
	int i = 0;
	cin.getline(inputHolder, 82);//gets the input
	while (count1 < 9)//inputs the values into the array
	{//count1 will represent row
		count2 = 0;//count2 will represent column
		while (count2 < 9)
		{			
			if(inputHolder[i] == 46){//unknown input will be '.' ascii 46
				puzzle[count1][count2].knownValue = 0;
				for(int a=0; a<9; a++) //init all values in holder to 0
				puzzle[count1][count2].holder[a] = 0;}			
			else
				puzzle[count1][count2].knownValue = inputHolder[i] - 48;//changes from ascii to int
			count2++;
			i++;
		}
		count1++;
	}

I need to pass this array into a function that will begin to solve the sudoku puzzle but I don't know how to pass a 2 dimensional array of type Stack. Any input would be greatly appreciated. I am pretty sure that I won't have to return the array because of the way c++ handles arrays being passed into functions. It is my understanding that if an array is passed into a function any changes to the array will be reflected globally. Am I on the right track? Can anyone help?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
using namespace std;

void foo(int p[9][9])
{
    for (int i=0; i<9; i++) //fixed, length should be constant
        for (int k=0; i<9; i++) {
            p[i][k];
        }
}

void boo(int* p) //not really 2d
{
    for (int i=0; i<9; i++)
        for (int k=0; i<9; i++) {
            p[i*9+k];
        }
}

int main()
{
    int sudoku1[9][9];
    foo(sudoku1);

    int sudoku2[9*9];
    boo(sudoku2);
    return 0;
}

//You just have to change int to your stack class 


I'm just wondering if size==9? Cause if Stack hold 9 values and you makes 9X9 instance of that. It can hold 9x9x9 values.
Topic archived. No new replies allowed.