-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
35 lines (31 loc) · 1.43 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gubranco <gubranco@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/16 19:21:33 by gubranco #+# #+# */
/* Updated: 2022/12/04 16:01:15 by gubranco ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *str;
size_t i;
size_t j;
if (s1 == NULL || s2 == NULL)
return (NULL);
i = ft_strlen(s1);
j = ft_strlen(s2);
str = (char *)malloc((ft_strlen(s1) + ft_strlen(s2) + 1) * sizeof(char));
if (str == NULL)
return (NULL);
ft_strlcpy(&str[0], s1, i + 1);
ft_strlcpy(&str[i], s2, j + 1);
return (str);
}
/* Allocates (with malloc(3)) and returns a new string, which is the result
of the concatenation of ’s1’ and ’s2’.
It returns the new string, and NULL if the allocation fails.*/