title: Values of array randomly change
body: <p>So I have a text file which has information about basketball players and it looks like this:</p>
  
  <pre><code>8
  9 5 7 -5 13 -4 11
  7 5 -3 12 -5 17 -3
  25 7 12 -3 5 -5 7 -5 3
  14 5 12 -3 10 -7 8
  5 1 -40
  33 5 15 -5 9 -3 8
  11 5 -12 8 -5 12 -3
  13 5 3 -4 25 -5 3
  </code></pre>
  
  <p>First integer in the first line shows how many players are there. In every other line the first integer is the number of the player, the second integer shows how many more integers there are in the line and each of the following integers shows if the player is playing (if the integer is positive) or sitting on the bench (if the number is negative). </p>
  
  <p>I want to read the info to an array of structures which look like this:</p>
  
  <pre><code>struct player
  {
      int nr;
      int k;
      int bus[];
  };
  </code></pre>
  
  <p>I've written a function to do so:</p>
  
  <pre><code>void skaitymas(int &amp;n, player mas[])
  {
      ifstream duom("U1.txt");
      duom &gt;&gt; n;
      for (int i=0; i &lt; n; i++) {
          duom &gt;&gt; mas[i].nr &gt;&gt; mas[i].k;
          for (int f=0; f &lt; mas[i].k; f++) {
              duom &gt;&gt; mas[i].bus[f];
          }
      }
  }
  </code></pre>
  
  <p>When I run it the program seems to work, however the arrays of structures save unexpected values. After adding some <code>cout</code> commands in random places, I found out that it saves the correct values to the array the first time, first for loop loops, but after some iterations it changes the values of the previous arrays. For example, when <code>i</code> in the for loop equals <code>1</code> then <code>mas[1].bus[0]</code> is saved to be <code>-3</code>, as it should be, however after <code>i</code> changes to <code>2</code>, <code>mas[1].bus[0]</code> changes to <code>25</code>. </p>
  
  <p>I would appreciate it if you would help me to figure it out, why the numbers in the arrays change to other random numbers from the text file, even if I don't do anything to them.</p>