Libft
42 Libft library documentation
Loading...
Searching...
No Matches
ft_strjoin.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_strjoin.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: raphalme <raphalme@student.42.fr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/12/29 19:03:00 by raphalme #+# #+# */
9/* Updated: 2026/04/14 10:45:22 by raphalme ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "../includes/libft.h"
14
22char *ft_strjoin(char const *s1, char const *s2)
23{
24 char *join;
25 size_t len1;
26 size_t len2;
27
28 if (!s1 || !s2)
29 return (NULL);
30 len1 = ft_strlen(s1);
31 len2 = ft_strlen(s2);
32 join = (char *)malloc(sizeof(char) * (len1 + len2 + 1));
33 if (!join)
34 return (NULL);
35 ft_memcpy(join, s1, len1);
36 ft_memcpy(join + len1, s2, len2);
37 join[len1 + len2] = '\0';
38 return (join);
39}
char * ft_strjoin(char const *s1, char const *s2)
Concatenates two strings into a newly allocated string.
Definition ft_strjoin.c:22
void * ft_memcpy(void *dest, const void *src, size_t n)
Copies bytes from source to destination.
Definition ft_memcpy.c:25
size_t ft_strlen(const char *str)
Returns the length of a null-terminated string.
Definition ft_strlen.c:21