title: Copy part of a char pointer to another one
body: <p>I have a pointer like this:</p>
  
  <p><code>const u_char *packet;</code></p>
  
  <p>And from the 42 elements to a certain point I have to copy it in another char pointer.</p>
  
  <pre><code>u_char *payload = new u_char[];
  
  int j = 0, l = 0;
  while (j &lt; header-&gt;caplen - 42 - 1) {
    if (j &gt;= 42){
      payload[l] = packet[j];
      l++;
    }
    j++;
  }
  payload[l] = '\0';
  </code></pre>
  
  <p>It works fine but then at a certain packet it gives me this error:</p>
  
  <pre><code>Unhandled exception at 0x55B3FB53 (msvcr120d.dll) in eval_waic.exe: 0xC0000005: Access violation reading location 0xCCCCCCCC
  </code></pre>
  
  <p>Any idea why? It works fine til that packet! i checked, its not packet's fault..</p>