forked from josanri/Libft_extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
36 lines (33 loc) · 1.54 KB
/
ft_strjoin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aalvarez <aalvarez@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/17 03:19:28 by aalvarez #+# #+# */
/* Updated: 2022/08/17 20:23:00 by aalvarez ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
/**
* @brief concatenates the string pointed by s1 and the string pointed
* by s2 and allocates a new string based on the result of the concatenation.
*
* @param s1 the first string to concatenate.
* @param s2 the second string to concatenate.
* @return char* the allocated string resultant of the concatenation.
*/
char *ft_strjoin(const char *s1, const char *s2)
{
char *str;
if (!s1 || !s2)
return (NULL);
str = (char *)malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
if (!str)
return (NULL);
ft_strlcpy(str, s1, (ft_strlen(s1) + 1));
ft_strlcat(str, s2, (ft_strlen(s1) + ft_strlen(s2) + 1));
return (str);
}