title: C++ Char pointer to char array
body: <p>None of the posted answers I've read work, so I'm asking again.</p>
  
  <p>I'm trying to copy the <s>string</s> data pointed to by a char pointer into a char array.</p>
  
  <p>I have a function that reads from a ifstream into a char array</p>
  
  <pre><code>char* FileReader::getNextBytes(int numberOfBytes) {
      char *buf = new char[numberOfBytes];
  
      file.read(buf, numberOfBytes);
  
      return buf;
  }
  </code></pre>
  
  <p>I then have a struct :</p>
  
  <pre><code>struct Packet {
      char data[MAX_DATA_SIZE]; // can hold file name or data
  } packet;
  </code></pre>
  
  <p>I want to copy what is returned from getNextBytes(MAX_DATA_SIZE) into packet.data;</p>
  
  <p><strong>EDIT:</strong> Let me show you what I'm getting with all the answers gotten below (memcpy, strcpy, passing as parameter). I'm thinking the error comes from somewhere else. I'm reading a file as binary (it's a png). I'll loop while the fstream is good() and read from the fstream into the buf (which might be the data array). I want to see the length of what I've read :</p>
  
  <pre><code>cout &lt;&lt; strlen(packet.data) &lt;&lt; endl;
  </code></pre>
  
  <p>This returns different sizes every time:
  8
  529
  60
  46
  358
  66
  156
  After that, apparently there are no bytes left to read although the file is 13K + bytes long.</p>