title: Variable Value Changes By Itself
body: <p>I've been pretty confused while programming before, but this one takes the cake. Basically I set the value in one for loop, and in the following iteration it changes to the value of the next one.</p>
  
  <pre><code>for (int i = 0; i &lt; 2; ++i)
  {
      for (int j = 0; j &lt; numWords[i]; ++j) //numWords [0] = 9, numWords [1] = 7
      {
          stb[i][j].word = const_cast&lt;char*&gt;(is (j + 1,1).c_str()); //is(int,length[opt]) converts int to string, c_str() returns const char *, but I need char *
          cout &lt;&lt; is(j+1,1) &lt;&lt; ' ' &lt;&lt; stb[i][j].word &lt;&lt; '\n';
      }
  }
  
  for (int i = 0; i &lt; 2; ++i)
  {
      for (int j = 0; j &lt; numWords [i]; ++j)
      {
          cout &lt;&lt; stb[i][j].word &lt;&lt; ' ';
      }
      cout &lt;&lt; '\n';
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre>
  1 1
  2 2
  3 3
  4 4
  5 5
  6 6
  7 7
  8 8
  9 9
  1 1
  2 2 
  3 3
  4 4
  5 5 
  6 6
  7 7 
  7 7 7 7 7 7 7 7 7
  7 7 7 7 7 7 7
  </pre>
  
  <p>My only guess now is something with the const, but it doesn't make sense why it would keep changing all previous array elements...</p>