char status = 'f';
char arr1[11][11];
char arr2[11][11];
......
do{
......
for(int x=0; x<11; x++){
for(int y=0; y<11; y++){
if(temp[x][y]!=store[x][y]){
status='f';
}
else{
status='t';
}
}}
}
while(status != 'f');
......
上面是我的 do
-while
循环代码。
据我所知,当while
中的条件为真时,程序应该再次从do
运行。
假设我的理解是正确的,当temp[x][y]
不等于store[x][y]
时,程序应该让 status = 'f'
并且循环继续。一旦 temp
和 store
相等,status = 't'
循环就会结束。
我现在的问题是,虽然我能够处理循环,但即使 temp
和 store
相等,循环也不会结束。我做错了什么?
谢谢!
最佳答案
else{
status='t';
break;
}
将确保您不会覆盖曾经更改的状态
。否则它会被覆盖。
还有第一个 for 循环内的另一个检查
if(status=='t')break;
代码将是
do{
status = 't'; // denotes that they are equal intiially.
......
for(int x=0; x<11; x++) {
for(int y=0; y<11; y++) {
if(temp[x][y]!=store[x][y]) {
status='f'; // they are not equal
}
}
if( status == 'f')
break;
}
} while(status == 'f');
关于在不使用 strcmp 的情况下比较 C 中的二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47368750/