title: Concatenating strings in C, which method is more efficient?
body: <p>I came across these two methods to concatenate strings:</p>
  
  <p>Common part:</p>
  
  <pre><code>char* first= "First";
  char* second = "Second";
  char* both = malloc(strlen(first) + strlen(second) + 2);
  </code></pre>
  
  <p>Method 1:</p>
  
  <pre><code>strcpy(both, first);
  strcat(both, " ");       // or space could have been part of one of the strings
  strcat(both, second);
  </code></pre>
  
  <p>Method 2:</p>
  
  <pre><code>sprintf(both, "%s %s", first, second);
  </code></pre>
  
  <p>In both cases the content of <code>both</code> would be <code>"First Second"</code>.</p>
  
  <p>I would like to know which one is more efficient (I have to perform several concatenation operations), or if you know a better way to do it.</p>