title: Ways to build string in c
body: <p>I'm building a string here based on 4 arguments and calling it with system(), but seems kinda messy the way i have done it. Is there a more correct way i should have done this and not use all those strcat and str1-4? </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main(int argc, char *argv[])
  {
  
      char str1[40] = "sed -n 's/.*\\(";
      char str2[] = "\\)\\(.*\\)\\(";
      char str3[] = "\\).*/\\2/p' ";
      char str4[] = " &gt; ";
  
      if (argc != 5)
      {
          fprintf (stderr, "Usage %s &lt;LogFile&gt; &lt;token1&gt; &lt;token2&gt; &lt;DumpFile&gt;\n",
                  argv[0]);
                  exit(EXIT_FAILURE);
      }
  
      strcat(str1, argv[2]);
      strcat(str1, str2);
      strcat(str1, argv[3]);
      strcat(str1, str3);
      strcat(str1, argv[1]);
      strcat(str1, str4);
      strcat(str1, argv[4]);
  
      system(str1);
  
      return 0;
  }
  </code></pre>