-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
39 lines (35 loc) · 1.55 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: lclerc <lclerc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/09 13:20:30 by lclerc #+# #+# */
/* Updated: 2022/11/24 11:04:39 by lclerc ### ########.fr */
/* */
/* ************************************************************************** */
/*
* ft_strjoin() is returning a new string out of the concatenation of s1 and s2.
*
* s1 is the prefixed string, and s2 the suffix.
*
* The returned value is NULL if allocation fails.
*
* Malloc can be used.
* */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *joined_string;
size_t joined_string_length;
if (!s1 || !s2)
return (NULL);
joined_string_length = ft_strlen(s1) + ft_strlen(s2) + 1;
joined_string = (char *)malloc(joined_string_length * sizeof(char) + 1);
if (joined_string == NULL)
return (NULL);
ft_strlcpy(joined_string, s1, joined_string_length);
ft_strlcat(joined_string, s2, joined_string_length);
return (joined_string);
}