fractol/libft/src/ft_strjoin.c
2023-03-01 04:36:42 +01:00

43 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ */
/* By: djonker <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2020/11/11 16:17:34 by djonker #+# #+# */
/* Updated: 2023/02/07 00:40:50 by houtworm ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
int c1;
int c2;
char *r;
c1 = 0;
c2 = 0;
if (s1 == NULL)
return (ft_malstr((char *)s2, '\0'));
if (s2 == NULL)
return (ft_malstr((char *)s1, '\0'));
r = ft_calloc(ft_strlen((char *)s1) + ft_strlen((char *)s2) + 1, 1);
if (r == NULL)
return (r);
while (c1 < (int)ft_strlen((char *)s1))
{
r[c1] = s1[c1];
c1++;
}
while (c2 < (int)ft_strlen((char *)s2))
{
r[c1 + c2] = s2[c2];
c2++;
}
r[c1 + c2] = '\0';
return (r);
}