-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
49 lines (45 loc) · 1.44 KB
/
ft_strjoin.c
File metadata and controls
49 lines (45 loc) · 1.44 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mobouifr <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 16:00:55 by mobouifr #+# #+# */
/* Updated: 2023/12/10 11:47:03 by mobouifr ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
size_t i;
size_t j;
char *s3;
i = 0;
j = 0;
if (!s1 && !s2)
return (NULL);
if (!s1 && s2)
return (ft_strdup(s2));
else if (!s2 && s1)
return (ft_strdup(s1));
s3 = malloc(ft_strlen(s1) + ft_strlen(s2) + 1);
if (!s3)
return (NULL);
while (s1[i] != '\0')
s3[j++] = s1[i++];
i = 0;
while (s2[i] != '\0')
s3[j++] = s2[i++];
s3[j] = '\0';
return (s3);
}
/*
int main(void)
{
const char s1[] = "be free ";
const char s2[] = "as a bee";
printf("%s", ft_strjoin(s1, s2));
return (0);
}
*/