title: C - comparing array of chars with a char
body: <p>Disclaimer - this is some homework, so I don't want the answer, but don't have anyone to go to to get some guidance (unless I wan to wait a week, I study via correspondence).</p>
  
  <p>Anyway, I am writing a little minesweeper function. The user enters the size of the grid and the number of mines. I then print out the board &amp; the results. For example, on a 3 * 3 board with 2 mines, I would print:</p>
  
  <pre><code>...
  *..
  ..*
  
  110
  *11
  10*
  </code></pre>
  
  <p>The * being the mines obviously. All is pretty well, except for the results. My comparison doesn't seem to work. I am comparing chars using the == symbol, which appears a perfectly legal way to do this, but the results don't make sense to me.</p>
  
  <p>I don't want the answers, just a point in the right direction. Potentially because I am comparing my array outside the bounds of the original array I set up. If this is the case, then I have no idea how to solve this problem.</p>
  
  <p>My code is below. Thanks!</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void number1(int *stats);
  void number2(int *stats);
  
  int main(void)
  {
     int n,m,i,j,k,x, rand1, rand2, counter, numMines;
     char choice;
  
  do
  
  {
     printf("------------\n");
     printf("lines (m) = : ");
     scanf("%d", &amp;m);
     printf("\ncolumns (n) = : ");
     scanf("%d", &amp;n);
     printf("\nMines = :");
     scanf("%d", &amp;numMines);
  
     // check to ensure that numMines is not &gt; n * m
     if (numMines &gt; m * n )
     {
        printf("Error. You cann't have more mines than available spaces ");
        break;
     }
  
     counter = 0;
     //create minefield array
  
     char mineGrid[n][m];
  
      //set all fields in minesweeper to safe (.)
  
     for (j = 0; j &lt; n; j++)
     {
        for (i = 0; i &lt; m; i++)
        {
           mineGrid[j][i] = '.';
        }
      }
      // Need to randomally make some mines for the array
      //bounds of the random numbers is defined by the values of n and m
  
     for (i = 0; i &lt; numMines; i++)
     {
        //generate random number
        rand1 = ((double)rand() / ((double)RAND_MAX + 1) * n);
        rand2 = ((double)rand() / ((double)RAND_MAX + 1) * m);
        //set as a mine:
        mineGrid[rand1][rand2] = '*';
  
        //Note : at the moment, mines can overlap. need to come back to fix this up.
      }
     //print out the msweeper grid
     x = 0;
     for (j = 0; j &lt; n; j++)
     {
        printf("\n");
        x++;
        for (i = 0; i &lt; m; i++)
        {
           printf("%c", mineGrid[j][i]);
        }
           printf("     ");
      }
  
     // here is where I will print the results:
     printf("\n");
     for (j = 0; j &lt; n; j++)
     {
        for (k = 0; k &lt; m; k++)
        {
  
        if (mineGrid[x+0][k+1]=='*')
           counter++;
        if (mineGrid[x+0][k-1]=='*')
           counter++;
        if (mineGrid[x+1][k+0]=='*')
           counter++;
        if (mineGrid[x+1][k-1]=='*')
           counter++;
        if(mineGrid[x+1][k+1]=='*')
           counter++;
        if (mineGrid[x-1][k+0]=='*')
           counter++;
        if (mineGrid[x-1][k-1]=='*')
           counter++;
        if(mineGrid[x-1][k+1]=='*')
           counter++;
  
        printf("%d", counter);
        counter = 0;
        }
  
     printf("\n");
  
     }
  
     printf("\n\nTry again? (y/n:) ");
     scanf("\n%s", &amp;choice);
  
  }while(choice == 'y' || choice == 'Y');
  }
  </code></pre>