42_solong/libftx/extra/ft_strfjoin.c

40 lines
1.3 KiB
C
Raw Normal View History

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