42_cub3d/Libft/ft_strjoin.c
2024-10-09 03:35:09 +02:00

41 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 16:41:00 by grobledo #+# #+# */
/* Updated: 2023/02/14 16:41:02 by grobledo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
size_t i;
size_t j;
char *dest;
if (!s1 || !s2)
return (NULL);
dest = ft_calloc ((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof (char));
if (dest == 0)
return (NULL);
i = 0;
j = 0;
while (s1[i] || s2[j])
{
while (i < ft_strlen(s1))
{
dest[i] = s1[i];
i++;
}
while (j < ft_strlen(s2))
{
dest[i + j] = s2[j];
j++;
}
}
return (dest);
}