-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
43 lines (38 loc) · 1.33 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
42
43
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amahla <amahla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 12:34:51 by amahla #+# #+# */
/* Updated: 2022/05/02 12:35:05 by amahla ### ########.fr */
/* */
/* ************************************************************************** */
#include"libft.h"
static int ft_slen(char const *str)
{
int i;
i = 0;
while (str && *(str + i))
i++;
return (i);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *dst;
size_t i;
size_t j;
i = 0;
j = 0;
dst = malloc((ft_slen(s1) + ft_slen(s2) + 1) * sizeof(char));
if (!dst)
return (NULL);
while (s1 && *(s1 + j))
*(dst + i++) = *(s1 + j++);
j = 0;
while (s2 && *(s2 + j))
*(dst + i++) = *(s2 + j++);
*(dst + i) = '\0';
return (dst);
}