title: How to copy a buffer to a character pointer in C
body: <p>So I have a character array of fixed size: </p>
  
  <pre><code>char buff[100];
  </code></pre>
  
  <p>And I have a character pointer:</p>
  
  <pre><code>char *ptr;
  </code></pre>
  
  <p>Now, the buffer will be filled partially or fully. I want to copy the contents of the buffer to ptr. How do I do that?</p>
  
  <p>Thanks</p>
  
  <p>Update:   </p>
  
  <pre><code>int rcd; // Received bytes
  int temp = 0; // This is used as a size to realloc the dataReceived character pointer
  int packetLength = 0; // This is the total packet length
  int *client = (int*) data;
  int cli = *client; // The client socket descriptor
  char buff[100]; // Buffer holding received data
  char *dataReceived = malloc(0);
  
  while ((rcd = recv(cli, buff, 100, MSG_DONTWAIT)) &gt; 0) 
  {
      dataReceived = realloc(dataReceived, rcd + temp + 1); // Realloc to fit the size of received data
      strcat(dataReceived, buff); // Concat the received buffer to dataReceived
      temp = rcd;
      packetLength = packetLength + rcd;
      memset(buff, 0, 100); // Reinitialize the buffer for the next iteration
  }
  </code></pre>