-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
37 lines (34 loc) · 1.36 KB
/
ft_strjoin.c
File metadata and controls
37 lines (34 loc) · 1.36 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
32
33
34
35
36
37
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oishchen <oishchen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/13 17:09:12 by oishchen #+# #+# */
/* Updated: 2025/03/23 11:40:26 by oishchen ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_strjoin(char const *s1, char const *s2)
{
int len_s1;
int len_s2;
char *joined;
if (!s1 || !s2)
return (NULL);
len_s1 = ft_strlen(s1);
len_s2 = ft_strlen(s2);
if (len_s1 == 0 && len_s2 == 0)
{
joined = ft_calloc(1, 1);
return (joined);
}
joined = (char *)malloc(sizeof(char) * (len_s1 + len_s2 + 1));
if (!joined)
return (NULL);
ft_strlcpy(joined, s1, len_s1 + 1);
ft_strlcpy(joined + len_s1, s2, len_s2 + 1);
return (joined);
}