-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
52 lines (47 loc) · 1.58 KB
/
Copy pathft_strjoin.c
File metadata and controls
52 lines (47 loc) · 1.58 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
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: user <user@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/29 15:30:00 by user #+# #+# */
/* Updated: 2023/04/29 15:30:00 by user ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
unsigned char *join;
size_t i;
size_t j;
j = 0;
i = 0;
if (!s1 && !s2)
return (ft_strdup(""));
else if (s1 && !s2)
return (ft_strdup(s1));
else if (!s1 && s2)
return (ft_strdup(s2));
join = (unsigned char *)ft_calloc(1, sizeof(unsigned char)
* (ft_strlen(s1) + ft_strlen(s2) + 1));
if (!join)
return (NULL);
while (s1[i])
join[j++] = (unsigned char)s1[i++];
i = 0;
while (s2[i])
join[j++] = (unsigned char)s2[i++];
join[j] = '\0';
return ((char *)join);
}
char *ft_strjoin_and_free(char **s1, char **s2)
{
char *rtn;
rtn = ft_strjoin(*s1, *s2);
free(*s1);
*s1 = NULL;
free(*s2);
*s2 = NULL;
return (rtn);
}