-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
50 lines (45 loc) · 1.34 KB
/
ft_strjoin.c
File metadata and controls
50 lines (45 loc) · 1.34 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: knzeng-e <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/03/21 20:06:48 by knzeng-e #+# #+# */
/* Updated: 2016/04/01 01:35:22 by knzeng-e ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_size(char const *s)
{
int i;
i = 0;
while (s[i])
i++;
return (i);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *join;
int i;
int j;
if (!s1 || !s2)
return (NULL);
i = ft_size(s1) + ft_size(s2);
if (!(join = (char *)malloc(sizeof(char) * (i + 1))))
return (NULL);
i = 0;
while (s1[i])
{
join[i] = s1[i];
i++;
}
j = 0;
while (s2[j])
{
join[i + j] = s2[j];
j++;
}
join[i + j] = '\0';
return (join);
}