I have the following code that concats two strings:
char *getConcatString(char *str1, char *str2) {
char *finalString = malloc(1 + strlen(str1) + strlen(str2)); // Needs to be freed by the user after use
if(finalString == NULL)
return NULL;
strcpy(finalString, str1);
strcat(finalString, str2);
return finalString;
}
Is there a more safe way to do this? Like for ex. strncat and strncpy? Thanks
The only thing I would do with the function is changing its parameter declarations and adding a check to NULL of the parameters.
For example