Repository navigation
Expand file tree
/
Copy pathft_strjoin.c
More file actions
56 lines (50 loc) · 1.52 KB
/
Copy pathft_strjoin.c
File metadata and controls
56 lines (50 loc) · 1.52 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
53
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smasatak <smasatak@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/11 13:48:51 by smasatak #+# #+# */
/* Updated: 2026/06/11 13:29:34 by smasatak ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *res;
char *dst;
if (!s1 || !s2)
return (NULL);
res = (char *)malloc((ft_strlen(s1) + ft_strlen(s2) + 1) * sizeof(char));
if (!res)
return (NULL);
dst = res;
while (*s1)
{
*dst = *s1;
dst++;
s1++;
}
while (*s2)
{
*dst = *s2;
dst++;
s2++;
}
*dst = '\0';
return (res);
}
// int main(void)
// {
// const char str1[] = "Hello";
// const char str2[] = "42Tokyo";
// printf("str1:%s, str2:%s\n", str1, str2);
// char *result = ft_strjoin(str1, str2);
// if (result)
// {
// printf("Result: %s\n", result);
// free (result);
// }
// return (0);
// }