-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
29 lines (26 loc) · 1.32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbishop- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/12 14:58:34 by mbishop- #+# #+# */
/* Updated: 2021/09/12 14:58:36 by mbishop- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *str;
if (s1 == NULL || s2 == NULL)
return (NULL);
str = (char *)malloc(sizeof(str) * (ft_strlen(s1) + ft_strlen(s2) + 1));
if (str == NULL)
return (NULL);
ft_strlcpy(str, s1, ft_strlen(s1) + 1);
ft_strlcat(str, s2, ft_strlen(s1) + ft_strlen(s2) + 1);
return (str);
}
/* allocates and returns a new string which is the result of the concatenation
** of s1 and s2. */