-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
41 lines (36 loc) · 1.31 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
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vsoares- <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/14 19:18:04 by vsoares- #+# #+# */
/* Updated: 2024/11/18 23:08:02 by vsoares- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t my_strlen(const char *s)
{
size_t len;
if (!s)
return (0);
len = 0;
while (s[len])
len++;
return (len);
}
char *ft_strjoin(const char *s1, const char *s2)
{
char *str;
size_t s1_len;
size_t s2_len;
s1_len = my_strlen(s1);
s2_len = my_strlen(s2);
str = ft_calloc(s1_len + s2_len + 1, 1);
if (!str)
return (NULL);
ft_memcpy(str, s1, s1_len);
ft_memcpy(str + s1_len, s2, s2_len);
return (str);
}