title: Binary Search with matrix
body: <p>I have a matrix:
  <a href="https://i.stack.imgur.com/LKYl1.png" rel="nofollow noreferrer">pic of matrix</a></p>
  <p>I need to count with Binary Search how many capital letters are on matrix.
  This is my code:</p>
  <pre><code>#define _CRT_SECURE_NO_WARNINGS#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #define N 4
  #define M 4
  int bigLetters(char** mat);
  int main()
  {
      char mat[M][N] = { 'H','i','k','o','A','B','x','z','F','K','Z','m','A','d','e','f' };
      printf(&quot;%d&quot;, bigLetters(mat));
      return 0;
  }
  int bigLetters(char** mat)
  {
      int i, cnt = 0;
      int low, high, mid;
      for (i = 0;i &lt; M;i++)
      {
          low = 0;
          high = N - 1;
          while (low &lt;= high)
          {
              mid = (low + high) / 2;
              if (mat[i][mid] &gt;= 'a' &amp;&amp; mat[i][mid] &lt;= 'z') high = mid - 1;
              else if (mat[i][mid] &gt;= 'A' &amp;&amp; mat[i][mid] &lt;= 'Z' &amp;&amp; mat[i][mid + 1] &gt;= 'a' &amp;&amp; mat[i][mid + 1] &lt;= 'z')
              {
                  cnt = cnt + mid + 1;
                  low = high + 1;
              }
              else low = mid + 1;
          }
      }
      return cnt;
  }
  </code></pre>
  <p>The program is crashing in first If sentence.
  <a href="https://i.stack.imgur.com/WiMWx.png" rel="nofollow noreferrer">Screenshot of error</a></p>
  <p>What am I doing wrong?</p>