title: How to copy a string into middle of character pointer
body: <p>I have a dynamically allocated char array with pre_padding_buffer (size 8) and post_padding_buffer (size 6). I need to copy the string over to a character pointer like this:</p>
  
  <pre><code>[ ][ ][ ][ ][ ][ ][ ][ ][e][x][a][m][p][l][e][ ][ ][ ][ ][ ][ ]
  </code></pre>
  
  <p>The paddings are not optional and required by the specs of a machine I'm communicating with (it can be filled with empty/garbage data, it's overwritten anyways).</p>
  
  <p>Currently this is what I'm doing.</p>
  
  <pre><code>unsigned char *async_string = get_async_string();
  
  unsigned char *response_all_buf = (unsigned char*)malloc(LWS_SEND_BUFFER_PRE_PADDING + strlen(async_string) + LWS_SEND_BUFFER_POST_PADDING);
  
  //Copy string
  int i = 0;
  for (i = 0; i &lt; strlen(async_string); i++) {
      response_all_buf[LWS_SEND_BUFFER_PRE_PADDING + i] = async_string[i];
  }
  
  libwebsocket_write(wsi,respones_all_buf,strlen(async_string),LWS_WRITE_TEXT);
  free(response_all_buf); //&lt;-- Segmentation fault here
  </code></pre>
  
  <p>Segmentation fault must indicate that I'm not copying the string correctly. What's the correct way of doing this when you have paddings to insert before and after?</p>