Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Unexpected array change in c

  1. Dec 16, 2011 #1
    Code (Text):
    if(gameBoardState[i][col] == 0)
                gameBoardState[i][col] = playerTurn;
    This code is supposed to change the values in gameBoardState[col] (a 2D array), but it changes values in other elements too. For example, when col = 0, and i = 5, gameBoardState[4][6] is changed with the same value as well.
  2. jcsd
  3. Dec 16, 2011 #2

    How are you sure it's getting changed by this piece of code & not elsewhere?
    Did you check this in the debugger?

    Also what's the datatype of gameboardState, playerTurn, i & col?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook