title: Dynamic Array Output Problem
body: <p>I am working on a homework assignment where I had to convert all of the static arrays in a program into dynamic arrays using pointers. I am pretty sure I am understanding the concept, I have made the changes and my program runs. The problem is with my output results. I suspect I am inputting the data incorrectly from the file I am using. Here is a pic of my issue as well as relevent code:</p>
  
  <p>EDITS FROM 9/21 AFTER THIS POINT:</p>
  
  <p><strong>Output &amp; Data file:</strong>
  <img src="https://i.stack.imgur.com/qLsEh.png" alt="enter image description here"></p>
  
  <p><strong>main</strong> </p>
  
  <pre><code>#include "Ch9_Ex7.h"
  
  int main()
  {
      int numCandidates;
      string *allCandidates;
      int *votes;
      int index, totalVotes;
      ifstream infile;
  
      allCandidates = new string[1];
      votes = new int[1];
  
  
      infile.open("./Ch9_Ex7Data.txt");
      if (!infile)
      {
          cerr &lt;&lt; "Cannot open input file. Program terminates!" &lt;&lt; endl;
          return 1;
      }
  
  // read number of candidates
  
      readVotes (infile, votes, allCandidates, numCandidates);
  
      //delete [] votes;
      //delete [] allCandidates;
  </code></pre>
  
  <p><strong>Input Function:</strong></p>
  
  <pre><code>#include "Ch9_Ex7.h"
  
  void readVotes (ifstream &amp; infile, int *&amp;votes,
                  string *&amp;allCandidates, int &amp; numCandidates)
  {
  
  //    read number of candidates
      infile &gt;&gt; numCandidates;
      infile.ignore();  // carriage return
  
      //delete [] votes;
      //delete [] allCandidates;
  
      allCandidates = new string[numCandidates];
      votes = new int[numCandidates];
  
      for (int index = 0; index &lt; numCandidates; index++)
      {
          infile &gt;&gt; votes[index];
          infile.ignore();  // space
          getline(infile, allCandidates[index]);
      }
  
  }
  </code></pre>