-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
42 lines (39 loc) · 1.27 KB
/
ft_strjoin.c
File metadata and controls
42 lines (39 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strjoin.c :+: :+: */
/* +:+ */
/* By: mgraaf <mgraaf@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2021/12/16 14:24:11 by mgraaf #+# #+# */
/* Updated: 2021/12/16 14:24:13 by mgraaf ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
int len;
char *s1_2;
int i;
if ((!s1 || !s2) || (!s1 && !s2))
return (0);
len = ft_strlen(s1) + ft_strlen(s2);
s1_2 = (char *)malloc(len * sizeof(char) + 1);
i = 0;
if (!s1_2)
return (0);
while (*s1)
{
s1_2[i] = *s1;
s1++;
i++;
}
while (*s2)
{
s1_2[i] = *s2;
s2++;
i++;
}
s1_2[i] = '\0';
return (s1_2);
}