-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
37 lines (33 loc) · 1.4 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: antandre <antandre@student.42barcel> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 12:35:43 by antandre #+# #+# */
/* Updated: 2024/06/27 12:16:27 by antandre ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
#include <stddef.h>
/*
* Allocates memory using malloc() and returns a new string formed by
* concatenating s1 and s2.
* Copies s1 to the new string and then concatenates s2 to it.
*/
char *ft_strjoin(char const *s1, char const *s2)
{
char *str;
size_t len;
if (!s1 || !s2)
return (0);
len = ft_strlen(s1) + ft_strlen(s2);
str = (char *)malloc((len + 1) * sizeof(char));
if (str == NULL)
return (NULL);
ft_strlcpy(str, s1, len + 1);
ft_strlcat(str, s2, len + 1);
return (str);
}