I'm trying to search a 3x3 2d array diagonally, like this:
I want to check if all boxes in the diagonal have the same value. Here is how I try to do it:
thisOne = board[0][2]; //set to 'X'
for(i = 0; i<3; i++) {
for(j = 3; j>0; j--){
if(board[i][j-1] != thisOne) {
thisOne= '\0';
}
}
}
//since all boxes were 'X', thisOne is still set to 'X'
if(thisOne != '\0') {
winner = thisOne;
printf("vinnare på nördöst\n");
}
So after running this code, winner should be 'X', if all boxes are X's. But the code does not do that, why is that?