title: c++ pointer to array of strings
body: <p>Have a look at this code: I am trying to read in a number of strings from the console and store them in a dynamic array. </p>
  
  <pre><code>int Doctor::addPatients()
  {
    string* names = NULL;
    int num;
    cout &lt;&lt; "how many patients are to be added? ";
    cin &gt;&gt; num;
    numPatients=num;
    names = new string[numPatients];
    for(int i=0;i++;i&lt;numPatients){
      cout &lt;&lt; "enter the next patient's name: ";
      cin.clear();
      cin &gt;&gt; names[i];
    }
    patients = names; //patients is a private member variable of class Doctor
  }
  </code></pre>
  
  <p>When I execute this code, I get the following error:</p>
  
  <pre><code>malloc: *** error for object 0x10c100898: pointer being freed was not allocated
  *** set a breakpoint in malloc_error_break to debug
  Abort trap: 6
  </code></pre>
  
  <p>Any help is greatly appreciated</p>