-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin.c
49 lines (45 loc) · 1.5 KB
/
ft_strjoin.c
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: yeparra- <yeparra-@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/14 16:23:11 by yeparra- #+# #+# */
/* Updated: 2023/11/05 17:05:29 by yeparra- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
size_t len1;
size_t len2;
char *str;
len1 = ft_strlen(s1);
len2 = ft_strlen(s2);
str = malloc((len1 + len2 + 1) * sizeof(char));
if (str == NULL)
return (NULL);
ft_memcpy(str, s1, len1);
ft_memcpy(str + len1, s2, len2);
str[len1 + len2] = '\0';
return (str);
}
/*
int main()
{
char *str1 = "Hello,";
char *str2 = "World!";
char *result;
result = ft_strjoin(str1, str2);
if (result == NULL)
{
printf("Error: no se pudieron unir las cadenas\n");
}
else
{
printf("Concatenación de str1 y str2: %s\n", result);
free(result);
}
return (0);
}*/