-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
31 lines (28 loc) · 1.26 KB
/
ft_strjoin.c
File metadata and controls
31 lines (28 loc) · 1.26 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amarjan <amarjan@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/02 15:20:23 by amarjan #+# #+# */
/* Updated: 2025/11/02 17:49:26 by amarjan ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
size_t length;
size_t alloc_size;
char *p;
if (s1 == NULL || s2 == NULL)
return (NULL);
length = ft_strlen(s1) + ft_strlen(s2);
alloc_size = length * sizeof(char) + 1;
p = (char *)malloc(alloc_size);
if (p == NULL)
return (NULL);
ft_strlcpy(p, s1, ft_strlen(s1) + 1);
ft_strlcat(p, s2, alloc_size);
return (p);
}