-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
38 lines (35 loc) · 1.39 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
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sonyacorcoran <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/11 12:58:32 by sonyacorcor #+# #+# */
/* Updated: 2023/08/21 16:43:35 by sonyacorcor ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
size_t s1_len;
size_t s2_len;
size_t stot_len;
char *rtn;
if (!s1 && !s2)
return (ft_strdup(""));
if (s1 && !s2)
return (ft_strdup(s1));
if (!s1 && s2)
return (ft_strdup(s2));
s1_len = ft_strlen((char *)s1);
s2_len = ft_strlen(s2);
stot_len = s1_len + s2_len + 1;
rtn = malloc(sizeof(char) * stot_len);
if (!rtn)
return (0);
ft_memmove(rtn, s1, s1_len);
ft_memmove(rtn + s1_len, s2, s2_len);
rtn[stot_len - 1] = '\0';
return (rtn);
}