-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
49 lines (44 loc) · 1.47 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kyalexan <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/22 10:27:34 by kyalexan #+# #+# */
/* Updated: 2021/12/15 12:23:33 by kyalexan ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static char *ft_strcat(char *dest, const char *src)
{
int i;
int dest_len;
i = 0;
dest_len = ft_strlen(dest);
while (src[i])
{
dest[dest_len + i] = src[i];
i++;
}
dest[dest_len + i] = '\0';
return (dest);
}
char *ft_strjoin(char const *s1, char const *s2)
{
size_t len;
char *new_string;
if (s1 && s2)
{
len = ft_strlen(s1);
len += ft_strlen(s2);
new_string = malloc(sizeof(char) * (len + 1));
if (!new_string)
return (NULL);
ft_bzero(new_string, len + 1);
ft_strcat(new_string, s1);
ft_strcat(new_string, s2);
return (new_string);
}
return (NULL);
}