Returns the string resulting from assembling the array of strings.
The function frees the memory of the input strings after finishing.