-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
39 lines (36 loc) · 1.28 KB
/
ft_strjoin.c
File metadata and controls
39 lines (36 loc) · 1.28 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
38
39
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mait-elk <mait-elk@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/02 23:10:30 by mait-elk #+# #+# */
/* Updated: 2023/11/14 09:25:20 by mait-elk ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
size_t len;
char *res;
res = 0;
if (!s1 && !s2)
return (0);
if (!s1)
return (ft_strdup(s2));
if (!s2)
return (ft_strdup(s1));
len = ft_strlen(s1);
len += ft_strlen(s2);
res = malloc(len + 1);
len = 0;
if (!res)
return (0);
while (*s1)
res[len++] = *s1++;
while (*s2)
res[len++] = *s2++;
res[len] = '\0';
return (res);
}