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?? :/
//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].