-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
executable file
·50 lines (45 loc) · 1.54 KB
/
ft_strjoin.c
File metadata and controls
executable file
·50 lines (45 loc) · 1.54 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
40
41
42
43
44
45
46
47
48
49
50
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gyong-si <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/14 17:23:41 by gyong-si #+# #+# */
/* Updated: 2023/09/15 11:45:28 by gyong-si ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_strjoin(char const *s1, char const *s2)
{
char *result;
size_t len1;
size_t len2;
if (!s1 && !s2)
return (ft_strdup(""));
if (s1 && !s2)
return (ft_strdup(s1));
if (!s1 && s2)
return (ft_strdup(s2));
len1 = ft_strlen(s1);
len2 = ft_strlen(s2);
result = (char *)malloc(sizeof(char) * (len1 + len2 + 1));
if (!result)
return (NULL);
ft_strlcpy(result, s1, len1 + 1);
ft_strlcat(result, s2, len1 + len2 + 1);
return (result);
}
/*
#include <stdio.h>
int main(void)
{
char *s1 = "Hello";
char *s2 = " World";
char *result;
result = ft_strjoin(s1, s2);
printf("%s\n", result);
free(result);
return (0);
} */