title: C, When I change the character in a single position of a 2D array a second positon also has its character changed
body: <p>I have just started learning C a day ago so apologies if the answer is obvious, or my code is terribly inefficient.</p>
  
  <p>I am creating a battleship game where 3 ships (a battleship, a destroyer, and a carrier) will be placed onto a board.</p>
  
  <p>The battleship will occupy 3 squares, the destroyer 2, and the carrier 5.</p>
  
  <p>The board is a 2 dimensional array of characters</p>
  
  <pre><code>    P1_board[9][9]
  </code></pre>
  
  <p>When a player wishes to place a ship on the board specific positions in the array will be changed to a character ('B' for battleship, 'D' for destroyer, and 'C' for carrier). A ship is placed onto the board through a subroutine called:</p>
  
  <pre><code>    PlaceShip(char Letter, char Number, char Ship, char Direction)
  </code></pre>
  
  <p>Where Letter will be a lowercase character from a to j, Number will be a number character from 1 to 10, Ship will be either 'B','D', or 'C' for the corresponding ship, and Direction will be either 'r' for right or 'd' for down.</p>
  
  <p>The problem I have is that when I try to place a ship on either the left or rand edges a position on the opposite side of the board is also changed.</p>
  
  <p>Example:
  When I run these C commands:</p>
  
  <pre><code>    PlaceShip('a', '2', 'C', 'r');
      PlaceShip('a', '7', 'B', 'd');
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/wXkgY.png" rel="nofollow noreferrer">Image: Carrier supposed to occupy a2 to e2 and battleship supposed to occupy a7 to a9</a></p>
  
  <p>If I now instead run these C commands:</p>
  
  <pre><code>    PlaceShip('c', '2', 'C', 'r');
      PlaceShip('b', '7', 'B', 'd');
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/PqBPO.png" rel="nofollow noreferrer">Image: the ships are away from the edges and no characters appear on opposite sides</a></p>
  
  <p>I thought that it could maybe be some sought of character overflowing into the next array position but i'm not sure how to fix that or if this is even the case.</p>
  
  <p>I am using Visual Studio Community 2015 edition's Visual C++ to compile and run C code.</p>
  
  <p>Below is the a simplified version of my full code which still produces the problem:</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      #define Board_Size 2
      Board[Board_Size][Board_Size];
      void main() {
              int i = 0, j = 0;
              for (i = 0; i &lt;= Board_Size; i++) {
              for (j = 0; j &lt;=Board_Size; j++) {
                      Board[i][j] = 'a';
                      printf("%c   ", Board[i][j]);
              }
              printf("\n");
      }
      printf("\n");
      Board[0][2] = 'b';
      //   [y][x]
      printf("\n");
      printf("%c   %c   %c\n", Board[0][0], Board[0][1], Board[0][2]);
      printf("%c   %c   %c\n", Board[1][0], Board[1][1], Board[1][2]);
      printf("%c   %c   %c\n", Board[2][0], Board[2][1], Board[2][2]);
      }
  </code></pre>