blob: 5c0bf41ad5df0f60367426a83c91e4e2b4629739 (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 10:15:33 by dkaiser #+# #+# */
/* Updated: 2025/01/22 00:27:04 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
// static int copy_str(char *dst, const char *src)
// {
// int i;
// i = 0;
// while (src[i])
// {
// dst[i] = src[i];
// i++;
// }
// return (i);
// }
char *ft_strjoin(const char *s1, const char *s2)
{
char *joined_str;
size_t len1;
size_t len2;
if (!s1 || !s2)
return (NULL);
len1 = strlen(s1);
len2 = strlen(s2);
joined_str = malloc(len1 + len2 + 1);
if (!joined_str)
return (NULL);
strcpy(joined_str, s1);
strcat(joined_str, s2);
return (joined_str);
}
/* #include <stdio.h> */
/* int main(void) */
/* { */
/* char s1[] = "Hello "; */
/* char s2[] = "World"; */
/* printf("%s\n", ft_strjoin(s1, s2)); */
/* } */
|