Last updated
Last updated
This function works basically the same way as ft_strlcat
does, but instead of passing it a destination
string
that has to be correctly allocated as a parameter, we only pass two strings
and ft_strjoin
will allocate the required memory for both of them plus the NUL-terminating character.
s1
will be the first string in the result, s2
the second one.
We have to get the length of both strings so we can allocate enough memory for both of them.
So that's the first thing to do. Then we can allocate enough memory for both string plus the NUL-terminating character.
We then copy s1
into our newly allocated string, then we copy s2
, and finally we can set the last character as NUL
.