I have this program where I want to check whether a sudoko is correct (you all know the simple rules:1->9 in each line, column and 3*3 square)
Below you will find the code of a function that gets a nice little 9*9 table and then has to check if all the lines are filled in correctly. However despite my best (thus probably not so great) efforts it still seems to think every wrong sudoku I throw at it is correct.
I am fully aware of the fact that this is totally useless and newbie (school) stuff but I'm trying to learn something and since learning from your mistakes is supposed to help you improve big time any help would be greatly appreciated!
Here's the code:
Code:
int rijtest (int sud[][9])
{
int i=0,j,k=0,a=0;
int tel[10];
while (k<11)
{
tel[k]=0;
k++;
}
for (i=0;i<9 && !a;i++)
{
for (j=0;j<9;j++)
{
switch (sud[i][j])
{
case 1:
tel[1]++; break;
case 2:
tel[2]++; break;
case 3:
tel[3]++; break;
case 4:
tel[4]++; break;
case 5:
tel[5]++; break;
case 6:
tel[6]++; break;
case 7:
tel[7]++; break;
case 8:
tel[8]++; break;
case 9:
tel[9]++; break;
default:
tel[0]++;
}
}
if (tel[0])
{
printf("unvalid number on row %d\n",++i);
a=100+i; //errorcode to return to main
}
else
{
k=0;
while (k<11 && !a)
{
if (tel[k] !=1)
{
printf("double number on row %d\n",++i);
a=100+10+i; //errorcode to return to main
}
}
}
}
return a;
}


I spent hours staring at that code, got some people (probably even worse coders than me) to take a look at it and it turns out to be so obvious... Goes to show the long path to enlightenment in front of me...