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?
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Unexpected array change in c
  1. Arrays in C++ (Replies: 10)

  2. Arrays c++ (Replies: 14)

  3. C++ Array (Replies: 10)

  4. C# arrays (Replies: 1)