title: c malloc() - do I need to allocate space for the null terminator
body: <p>I have a snippet of code below that appends the text <code>_dut1_serial_log.txt</code> to a supplied filename. The supplied filename is a variable in the struct pointed to by <code>targetP</code>. </p>
  
  <p>The text <code>_dut1_serial_log.txt</code> is 20 chars long. My question is do I need the <code>+1</code> when I call malloc for the null terminator? </p>
  
  <pre><code>char *filename_ending = "_dut1_serial_log.txt";
      char *filename_with_extension;
      prv_instance_t *targetP = threadParams-&gt;targetP;
  
      /*append filename ending "_dut1_serial_log.txt" to filename supplied*/
      filename_with_extension = malloc(strlen(targetP-&gt;output_filename)+1+20);
      strcpy(filename_with_extension, targetP-&gt;output_filename); /* copy name into the new var */
      strcat(filename_with_extension, filename_ending); /* add the extension */
  </code></pre>