title: C - 2D array detects too many neighbours from input
body: <p><strong>2D array neighbour problem</strong></p>
  
  <p>Hello!</p>
  
  <p>I've been working on this code for a Conway's game of life program and I'm running into a problem with the neighbour detecting function within my program. The input takes a matrix from the user of alive and dead cells, then parses it to detect neighbours using the function below, I understand I require some kind of shadow border to remove the excess neighbour problem but cannot figure out how to implement this. </p>
  
  <p><strong>Example of function for detecting neighbours:</strong></p>
  
  <pre><code>int neighbourCount(int row, int column, char grid[row][column]){
      int count = 0;
  
      if(grid[row-1][column-1] == 'X') {
          count++;
      }
      if(grid[row-1][column] == 'X') {
          count++;
      }
      if(grid[row-1][column+1] == 'X') {
          count++;
      }
      if(grid[row][column-1] == 'X') {
          count++;
      }
      if(grid[row][column+1] == 'X') {
          count++;
      }
      if(grid[row+1][column-1] == 'X') {
          count++;
      }
      if(grid[row+1][column] == 'X') {
          count++;
      }
      if(grid[row+1][column+1] == 'X') {
          count++;
      }
  
      return count;
  }
  </code></pre>
  
  <p><strong>Input for 2d array and array declaration</strong></p>
  
  <pre><code>char grid[row][column];
  
  int i, j;
  for(i=0; i&lt;row; i++) {
      for(j=0;j&lt;column;j++) {
          scanf(" %c", &amp;grid[i][j]);
      }
  }
  </code></pre>
  
  <p><strong>Example input:</strong></p>
  
  <p>XXX</p>
  
  <p>XXX</p>
  
  <p>XXX</p>
  
  <p><strong>Neighbour amount for first alive cell in 2d array</strong></p>
  
  <p>5</p>
  
  <p>Any feedback or additional parts of the code can be provided and I understand the code isn't the best it could be as I am fairly new to C, this problem has got me scratching my head and is disrupting the rest of my program. Any help would be much appreciated! Thank you for any future feedback/answers.</p>