-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
50 lines (45 loc) · 1.43 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
44
45
46
47
48
49
50
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nvillalt <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/05 15:07:13 by nvillalt #+# #+# */
/* Updated: 2023/10/06 13:21:08 by nvillalt ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static char *join_str(char *join, char const *s1, char const *s2)
{
int i;
int j;
i = 0;
j = 0;
while (s1[i] != '\0')
{
join[i] = s1[i];
i++;
}
while (s2[j] != '\0')
{
join[i] = s2[j];
j++;
i++;
}
join[i] = '\0';
return (join);
}
char *ft_strjoin(char const *s1, char const *s2)
{
size_t len;
char *join;
if (*s1 == '\0' && *s2 == '\0')
return (ft_strdup(""));
len = ft_strlen(s1) + ft_strlen(s2) + 1;
join = (char *)malloc(sizeof(char) * len);
if (!join)
return (0);
join = join_str(join, s1, s2);
return (join);
}