-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
50 lines (46 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
39
40
41
42
43
44
45
46
47
48
49
50
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aymoulou <aymoulou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/19 18:03:32 by aymoulou #+# #+# */
/* Updated: 2021/11/12 10:55:17 by aymoulou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_join(const char *s1, const char *s2)
{
char *join;
int i;
int j;
i = 0;
j = 0;
join = malloc((sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1)));
if (!(join))
return (NULL);
while (s1[i])
{
join[j] = s1[i];
i++;
j++;
}
i = 0;
while (s2[i])
{
join[j] = s2[i];
j++;
i++;
}
join[j] = '\0';
return (join);
}
char *ft_strjoin(char const *s1, char const *s2)
{
if (s1 == NULL)
return (ft_strdup(s2));
if (s2 == NULL)
return (ft_strdup(s1));
return (ft_join(s1, s2));
}