title: C++ Dynamic array of char arrays
body: <p>I am trying to make dynamic array of char arrays</p>
  
  <pre><code>const int nameLength = 10;
  int dataCount = 5;
  
  // Initialize array of char array
  char ** name;
  name = new char*[dataCount];
  for (int i = 0; i &lt; dataCount; i++)
      name[i] = new char[nameLength];
  
  // Prompt for names
  for (int i = 0; i &lt; dataCount; i++) {
      char userInput[nameLength];
      cout &lt;&lt; "Input data " &lt;&lt; i &lt;&lt; " :";
      cin &gt;&gt; userInput;
      name[i] = userInput;
  }
  cout &lt;&lt; endl;
  
  // Display data entered
  for (int i = 0; i &lt; dataCount; i++) {
      cout &lt;&lt; "Name" &lt;&lt; i &lt;&lt; " : " &lt;&lt; name[i] &lt;&lt; endl;
  }
  </code></pre>
  
  <p>But the output is wrong:</p>
  
  <pre><code>Input data 0 :abcde
  Input data 1 :fghij
  Input data 2 :klmno
  Input data 3 :pqrst
  Input data 4 :uvwxy
  
  Name0 : uvwxy
  Name1 : uvwxy
  Name2 : uvwxy
  Name3 : uvwxy
  Name4 : uvwxy
  </code></pre>
  
  <p>If I change the input part to this then it would work as expected:</p>
  
  <pre><code>    cin &gt;&gt; name[i];
  </code></pre>
  
  <p>But in my case I cannot directly enter the data to the variable like that.<br>
  Can anyone explain what's wrong with the code? I searched everywhere but it doesn't seems to help</p>