我想对角搜索一个3x3的二维数组,像这样:对角检查2d阵列?
我要检查,如果在对角线所有箱子具有相同的值。这里是我尝试这样做:
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");
}
所以运行此代码后,winner
应该是“X”,如果所有的箱子是X的。但是代码不这么做,为什么?
'为(I = 0,J = 3-1; I <3;我++,j--){如果(!板[i] [j] = thisOne){thisOne = '\ 0' ;打破; }}' – BLUEPIXY
@BLUEPIXY哦,我现在看到它为什么不起作用。谢谢!如果您希望我接受和赞成,您可以回答这些问题。 – Carlton