2D array doubt !!

Hi,

This code should check each column and each row in a 2D array, but it doesn't work it gives random numbers after the array and then the program stop working!!, how to solve it?? :/


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//a function to check the rows and columns 
void col_row(int sudok[][9],int siz)
{
    bool duplic = false;
	for(int i=0;i<siz;i++)
	{
		for(int j=0;j<siz;j++)
		{
			if(sudok[i]!= sudok[i+1])
				duplic = true;
			else
			{duplic = false;
			break;
			}
		}
		if(duplic == false)
			break;

	}
 if(duplic)
	 cout << "The Numbers are suitable for the game" << endl;
 else
	 cout << "The Numbers are Not good for the game" << endl;
}
what random numbers? numbers in sudok aren't modified by this function. what this function does is check if there aren't any two equal numbers one immediately after another. I don't know why you would wnat to check that though..
One problem is that if siz = 9, at some point i = 8 and i+1 = 9, so sudok[i+1] goes out of array bounds.
Another is that line 9 uses 2d array with only one []. Thus your are not comparing the integers but pointers. Make it sudok[i][j].


sorry,
each column and row should not contain more than one digit from 1-9 //this is what I want to check

Last edited on
Topic archived. No new replies allowed.