title: Strcpy does not copy an allocated character array
body: <p>Why does this not work:</p>
  
  <pre><code>SomeClass::SomeClass(char *lit) //Ctor
  {
      str = new char[strlen(lit)+1]; // str is a pointer to char in SomeClass
      strcpy(str,"have");
      cout &lt;&lt; str &lt;&lt; " " &lt;&lt; "In Ctor" &lt;&lt; " +Size=" &lt;&lt; strlen(str)&lt;&lt; endl;
  }
  </code></pre>
  
  <p>The above code shows a string with length 0. But this code works:</p>
  
  <pre><code>SomeClass::SomeClass(char *lit)
  {
      char newstr[strlen(lit)+1];
      strcpy(newstr,"have");
      cout &lt;&lt; newstr &lt;&lt; " " &lt;&lt; "In Ctor" &lt;&lt; " +Size=" &lt;&lt; strlen(newstr)&lt;&lt; endl;
  }
  </code></pre>
  
  <p><strong><a href="http://ideone.com/MBctI" rel="nofollow">Here</a></strong> is the complete code.</p>
  
  <p>EDIT:<br>
  Added the link to Ideone which OP removed after I answered the Question.<br>
  Without the link to source code, this Q &amp; answer to it is useless.</p>