title: How to fill an array with a sentence?
body: <p>For instance i have the sentence " I am Piet". I want to fill this sentence into an array in a way that I[0], am[1] Piet[2]. Below is the code i've made. The problem is that the sentence is filled in each element of the array. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  // function to populate my array
  void populateMyArray(string*myArray, string sentence, int size)
  {
  for (int i = 0; i &lt; size; i++)
  {
  *myArray = sentence;
      myArray++;
  }
  }
  
  // function to count works in the sentence
  int countWords(string x)
  {
  int Num = 0;
  char prev = ' ';
  
  for (unsigned int i = 0; i &lt; x.size(); i++) {
  
      if (x[i] != ' ' &amp;&amp; prev == ' ') Num++;
  
      prev = x[i];
  }
  return Num;
  }
  
  int main()
  {
  string sentence1;
  
  cout &lt;&lt; "Please enter a line of text:\n";
  getline(cin, sentence1);
  
  int nWords1 = countWords(sentence1);
  
  string *arr1 = new string[nWords1];
  
  populateMyArray(arr1, sentence1, nWords1); //populate array1
  
  for (int i = 0; i &lt; nWords1; i++)
  {
      cout &lt;&lt; "sentence one: " &lt;&lt; arr1[i] &lt;&lt; "\n";
  }
  
  system("PAUSE");
  }
  </code></pre>