在不使用 strcmp 的情况下比较 C 中的二维数组

标签 c if-statement multidimensional-array do-while stdio

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' 并且循环继续。一旦 tempstore 相等,status = 't' 循环就会结束。

我现在的问题是,虽然我能够处理循环,但即使 tempstore 相等,循环也不会结束。我做错了什么?

谢谢!

最佳答案

 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/

相关文章:

c - 编写一个返回列表中字符串位置的函数(C 代码)

c - 将指向数组的指针传递给函数

python - if语句,if string.count() = integer?

python - 如何使用 numpy 数组中的 RGBA 数据列表进行 alpha 合成?

javascript - 如何从多阵列中删除文件详细信息

您可以使用 Adob​​e 的 Alchemy 来执行批处理文件吗?

将 Char *ptr 转换为 Char *ptrArray[] 以在 qsort 中使用

python - 如何在图表中运行 elif 函数?

r - 避免来自 ifelse() 的 FALSE 部分的警告

java - 将 1D 转换为 2D java.lang.ArrayIndexOutOfBoundsException