-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
60 lines (57 loc) · 4.32 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahabachi <ahabachi@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 14:46:35 by ahabachi #+# #+# */
/* Updated: 2022/10/06 14:46:37 by ahabachi ### ########.fr */
/* */
/* ************************************************************************** */
/* */
/* ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ */
/* ▐░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ */
/* ▐░▌ ▀▀▀▀█░█▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀▀▀ ▀▀▀▀█░█▀▀▀▀ */
/* ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ */
/* ▐░▌ ▐░▌ ▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄▄▄ ▐░▌ */
/* ▐░▌ ▐░▌ ▐░░░░░░░░░░▌ ▐░░░░░░░░░░░▌ ▐░▌ */
/* ▐░▌ ▐░▌ ▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀▀▀ ▐░▌ */
/* ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ */
/* ▐░█▄▄▄▄▄▄▄▄▄ ▄▄▄▄█░█▄▄▄▄ ▐░█▄▄▄▄▄▄▄█░▌▐░▌ ▐░▌ */
/* ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░▌ ▐░▌ ▐░▌ */
/* ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀ ▀ */
/* */
/* ************************************************************************** */
/* █████████ ██████████ ██████████ ██████████ */
/* ██ ██ ██ ██ ██ ██ */
/* ██ ██ ██ ██ ██ */
/* ██ ██ ██ ██ */
/* ██ ██████████ ██████████ ██ */
/* ██ ██ ██ ██ */
/* ██ ██ ██ ██ */
/* ██ ██ ██ ██ */
/* ████████ ██████████ ██████████ ██ */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
int l1;
int l2;
char *s3;
if (s1 && !s2)
return (ft_strdup(s1));
if (!s1 && s2)
return (ft_strdup(s2));
if (!s1 && !s2)
return (0);
l1 = ft_strlen(s1);
l2 = ft_strlen(s2);
s3 = ft_calloc(l1 + l2 + 1, sizeof(char));
if (!s3)
return (s3);
ft_memmove(s3, s1, l1);
ft_memmove(s3 + l1, s2, l2);
return (s3);
}