42_solong/libftx/extra/ft_strfjoin.c
Camille Chauvet 909bb442b6 kekw
2023-01-04 20:07:13 +01:00

37 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strfjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 14:06:04 by cchauvet #+# #+# */
/* Updated: 2023/01/04 14:17:40 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "extra.h"
char *ft_strfjoin(char *s1, char *s2)
{
size_t i;
size_t y;
char *out;
out = malloc((ft_strlen(s1) + ft_strlen(s2) + 1) * sizeof(char));
if (out == NULL)
return (NULL);
i = -1;
if (s1 != NULL)
while (s1[++i] != '\0')
out[i] = s1[i];
free(s1);
y = -1;
if (s2 != NULL)
while (s2[++y] != '\0')
out[i + y] = s2[y];
free(s2);
out[i + y] = '\0';
return (out);
}