使用函数二维数组扫描对 [英] 2D array using a function to scan for pairs

查看:103
本文介绍了使用函数二维数组扫描对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造了这个功能,它可以扫描一个二维数组用于垂直对,其中行= 20,列= 30从澄清随机字符到Z存储在每个数组的元素。

I created this function that scans a 2D array for vertical pairs, where row = 20 and column = 30. To clarify random characters from A to Z are stored in each of the array's elements.

char function3 (char randchar_array[ROW] [COLUMN]) 

{
int r = 0 ;
int c = 0 ;
int vertpairs = 0;

 for (r = 0; r < ROW ; r++)
 {
     for (c = 0; c < COLUMN -1; c++)
     {
       {
       if(randchar_array[r][c] == randchar_array[r+1][c])
         vertpairs++;
       }
     }
  }

  return (vertpairs);
}

我的问题是:-1必要的第二个for语句为(C = 0;℃下COLUMN -1; C ++)。

My question is: Is the -1 necessary for the 2nd for statement " for (c = 0; c < COLUMN -1; c++)."

推荐答案

没有,从code(其中垂直比)似乎 - 1 应在外环代替

No, from the code (which compares vertically) it seems the - 1 should be on the outer loop instead.

现在它将比较在 randchar_array [ROW - 1 + 1]。[C] 这是出界,并给出了不确定的行为

Now it will compare at randchar_array[ROW - 1 + 1][c] which is out of bounds, and gives undefined behavior.

这篇关于使用函数二维数组扫描对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆