title: How to copy a block of memory containing null terminator in c++
body: <p>I have converted an image to byte array in C# and have sent it over TCP to a server application written in C++.</p>
  
  <p>Now I want to copy this byte array to another block of memory. I've tried <code>memcpy()</code> function but the problem is <code>memcpy</code> copy the memory block until it reaches a null terminator ('\0'), and the byte array contains many of null terminators and I want them to be copied too.</p>
  
  <p><strong>Update</strong></p>
  
  <p>For simplicity I've converter the string "Hello\0"World\0" in C# to a byte array using the following statement:</p>
  
  <pre><code>string s = "Hello\0"World\0";
  byte[] bytes = Encoding.UTF8.GetBytes(s);
  </code></pre>
  
  <p>I receive the bytes in an unsigned char* in c++ and copy it to another char pointer like this:</p>
  
  <pre><code>char *chars = new char[12];
  memcpy(chars , recvChar, MESSAGE_12);
  </code></pre>
  
  <p>but the char* results in "Hello";</p>