-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
33 lines (30 loc) · 1.3 KB
/
ft_strjoin.c
File metadata and controls
33 lines (30 loc) · 1.3 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ouboukou <ouboukou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/03 22:15:20 by ouboukou #+# #+# */
/* Updated: 2024/05/19 17:44:38 by ouboukou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(const char *s1, const char *s2)
{
size_t len;
char *str;
if (s1 == NULL || s2 == NULL)
return (NULL);
if (s1 == NULL && s2)
return (ft_strdup(s2));
if (s1 && s2 == NULL)
return (ft_strdup(s1));
len = ft_strlen(s1) + ft_strlen(s2);
str = malloc((len + 1) * sizeof(char));
if (str == NULL)
return (NULL);
ft_strlcpy(str, s1, len + 1);
ft_strlcat(str, s2, len + 1);
return (str);
}