Write the function my_strncat(). The function has three parameters: a char * s1, a const char * s2, and an int max, which represents the maximum size of the s1 buffer. Append the characters in s2 to the end of s1. Make sure you have only one '\0' at the end of the combined characters. Don't go beyond the end of the buffer you are asked to copy to. The function returns a pointer to the first character in s1.
My code does seem to give the right output, but I think the way I declare it wasn't very good,
can someone help me with a better code.
char * my_strncat(char * s1, const char * s2, int max)
{
char * p = new char[max];
for(int i = 0; i < strlen(s1); i++)
{
p[i] = s1[i];
}
int b = 0;
for(int i = strlen(s1); i < max; i++)
{
p[i] = s2[b];
b++;
}
s1 = p;
delete p;
return s1;
}