-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
52 lines (47 loc) · 1.35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khee-seo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/24 21:57:39 by khee-seo #+# #+# */
/* Updated: 2021/01/03 08:07:59 by khee-seo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int s_len(char const *s)
{
int len;
len = 0;
while (s[len])
len++;
return (len);
}
char *ft_strjoin(char const *s1, char const *s2)
{
int i;
int j;
int len;
char *new;
if (s1 == 0 || s2 == 0)
return (0);
len = s_len(s1) + s_len(s2) + 1;
if (!(new = (char *)malloc(sizeof(char) * len)))
return (0);
i = 0;
while (s1[i])
{
new[i] = s1[i];
i++;
}
j = 0;
while (s2[j])
{
new[i] = s2[j];
i++;
j++;
}
new[i] = '\0';
return (new);
}