-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
31 lines (28 loc) · 1.24 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adashyan <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/03 22:12:03 by adashyan #+# #+# */
/* Updated: 2022/05/08 18:31:29 by adashyan ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *joined;
size_t len1;
size_t len2;
if (!s1 || !s2)
return (0);
len1 = ft_strlen(s1);
len2 = ft_strlen(s2);
joined = (char *)malloc(sizeof(char) * (len1 + len2 + 1));
if (!joined)
return (0);
ft_strlcpy(joined, s1, len1 + 1);
ft_strlcat(joined, s2, len1 + len2 + 1);
return (joined);
}