How to easily append a string to another, which is dynamically allocated? strcat function is strangeful. Three times it appends strings well and the fourth time it does some crap.

Here is an example of code:
Code:
char* allocate(char* input) {
  int size = sizeof(vstup);
  char *output = new char[size];
  memcpy(output, input, size);  //or strcopy, doesn't matter
  return output;
}

char* formattedstring(char* string1, char* string2) {
  const char lbracket[2] = "(", divider[2] = ",", rbracket[2] = ")";
  char thestring[] = "";
  strcat(thestring, lbracket);
  strcat(thestring, string1);
  strcat(thestring, divider);
  strcat(thestring, string2);
  strcat(thestring, rbracket);
  /*I need to use this allocate function calling because I want to
    allocate thestring dynamically and because thestring variable
    is destroyed after this function (formatted string) finishes*/
  return allocate(thestring);
}

int main() {
  cout << formattedstring("1st", "2nd");
  return 0;
}
I know I should free up the memory after allocating it with "new". But I don't know how as I don't know how many times I will call the allocate function.
But it doesn't matter for me now. My question is how to append those 5 strings if the strcat function can't do the job?