-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
51 lines (46 loc) · 1.41 KB
/
ft_strjoin.c
File metadata and controls
51 lines (46 loc) · 1.41 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
51
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ppanchen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 12:51:44 by ppanchen #+# #+# */
/* Updated: 2017/02/19 20:31:38 by ppanchen ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *ret;
int i;
int j;
if (!s1)
return (ft_strdup(s2));
if (!s2)
return (ft_strdup(s1));
i = ft_strlen((char *)s1) + ft_strlen((char *)s2);
ret = (char *)malloc(i + 1);
if (!ret)
return (0);
i = -1;
while (s1[++i])
ret[i] = s1[i];
j = 0;
while (s2[j])
{
ret[i] = s2[j];
i++;
j++;
}
ret[i] = 0;
return (ret);
}
char *ft_strjoin_free(char **s1, char **s2)
{
char *str;
str = ft_strjoin(*s1, *s2);
ft_strdel(s1);
ft_strdel(s2);
return (str);
}