Files
mmoat/lib/libft/srcs/str/ft_strjoin.c
gazhonsepaskwa 09c2cb5b3e base struct
2025-01-13 13:21:53 +01:00

39 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 17:14:32 by nalebrun #+# #+# */
/* Updated: 2024/11/25 16:16:11 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
char *ft_strjoin(const char *s1, const char *s2)
{
char *out;
unsigned int i;
unsigned int j;
if (!s1 && !s2)
return (NULL);
if (!s1)
return (ft_strdup(s2));
if (!s2)
return (ft_strdup(s1));
out = ft_calloc(ft_strlen(s1) + ft_strlen(s2) + 1, sizeof(char));
if (!out)
return (NULL);
i = 0;
j = 0;
while (s1[j])
out[i++] = s1[j++];
j = 0;
while (s2[j])
out[i++] = s2[j++];
return (out);
}