forked from hidaehyunlee/Libft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
32 lines (29 loc) · 1.32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: daelee <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/02 21:05:35 by daelee #+# #+# */
/* Updated: 2021/01/02 23:34:56 by daelee ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char *s1, char *s2)
{
char *newstr;
int s1_len;
int s2_len;
if (!(s1) && !(s2))
return (NULL);
else if (!(s1) || !(s2))
return (!(s1) ? ft_strdup(s2) : ft_strdup(s1));
s1_len = ft_strlen(s1);
s2_len = ft_strlen(s2);
if (!(newstr = (char *)malloc(sizeof(char) * (s1_len + s2_len + 1))))
return (NULL);
ft_strlcpy(newstr, s1, s1_len + 1);
ft_strlcat(newstr + (s1_len), s2, s2_len + 1);
return (newstr);
}