34 lines
1.3 KiB
C
34 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strjoin.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/07/05 18:42:09 by whaffman #+# #+# */
|
|
/* Updated: 2024/07/10 14:49:11 by whaffman ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <stdlib.h>
|
|
#include "libft.h"
|
|
|
|
char *ft_strjoin(char const *s1, char const *s2)
|
|
{
|
|
char *str;
|
|
size_t len_s1;
|
|
size_t len_s2;
|
|
|
|
if (!s1 || !s2)
|
|
return (NULL);
|
|
len_s1 = ft_strlen(s1);
|
|
len_s2 = ft_strlen(s2);
|
|
str = (char *)malloc(len_s1 + len_s2 + 1);
|
|
if (!str)
|
|
return (NULL);
|
|
ft_memcpy(str, s1, len_s1);
|
|
ft_memcpy(str + len_s1, s2, len_s2);
|
|
str[len_s1 + len_s2] = '\0';
|
|
return (str);
|
|
}
|