title: strcat for unlimited string in c
body: <hr>
  
  <p>I want to implement strcat in c but for unlimited string, the function will allocate the necessary memory required for the final string, I came up with this :</p>
  
  <pre><code>char* strcat_ex(const char* str, ...) {
      if(!str)return 0;
  
      const char* current = str;
      char* res = 0;
      va_list args;
      va_start(args, str);
  
      // calculate the length of the final string
      size_t len = 0;
      for(; current; current = va_arg(args, char *))
          len += strlen(current);
  
      // allocate the string
      res = malloc(sizeof(char) * len + 1);
      if(!res)return 0;
  
      // copy the strings to the final destination
      size_t cur = 0;
      for(; current; current = va_arg(args, char *)) {
          size_t cur_len = strlen(current);
          memcpy_s(res + cur, cur_len, current, cur_len);
      }
  
      va_end(args);
      return res;
  }
  </code></pre>
  
  <ul>
  <li>Is there any standard function already implemented.</li>
  <li><p>If not how can I improve this code, for example :</p>
  
  <p>1-I am calculating the length of the strings twice, how can I calculate them only once.</p>
  
  <p>2-Is there any security issues.</p>
  
  <p>3-Other suggestion to improve the code.</p></li>
  </ul>