-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
43 lines (38 loc) · 1.43 KB
/
ft_strjoin.c
File metadata and controls
43 lines (38 loc) · 1.43 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mjusta <mjusta@student.42prague.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/27 18:08:41 by mjusta #+# #+# */
/* Updated: 2025/05/28 14:57:01 by mjusta ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *result;
size_t len1;
size_t len2;
if (s1 == NULL || s2 == NULL)
return (NULL);
len1 = ft_strlen(s1);
len2 = ft_strlen(s2);
result = (char *)malloc(len1 + len2 + 1);
if (!result)
return (NULL);
ft_memcpy(result, s1, len1);
ft_memcpy(result + len1, s2, len2);
result[len1 + len2] = '\0';
return (result);
}
/*
#include <stdio.h>
int main(void)
{
char *str1 = "Hello ";
char *str2 = "World ";
printf("%s\n", ft_strjoin(str1, str2));
printf("%s\n", ft_strjoin(str2, str1));
}*/