-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
39 lines (36 loc) · 1.29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hkrifa <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/26 12:01:04 by hkrifa #+# #+# */
/* Updated: 2021/04/08 11:47:03 by hkrifa ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
size_t i;
size_t len_s2;
char *dest;
if (!s1 || !s2)
return (NULL);
i = ft_strlen(s1);
len_s2 = ft_strlen(s2);
dest = malloc(sizeof(char) * (i + len_s2 + 1));
if (!dest)
return (NULL);
i = -1;
while (s1[++i])
dest[i] = s1[i];
len_s2 = -1;
while (s2[++len_s2])
{
dest[i] = s2[len_s2];
i++;
}
dest[i] = '\0';
return (dest);
}