39 lines
1.3 KiB
C
39 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strjoin.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/09/29 11:20:27 by cchauvet #+# #+# */
|
|
/* Updated: 2022/09/29 11:30:50 by cchauvet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strjoin(const char *s1, const char *s2)
|
|
{
|
|
char *out;
|
|
ssize_t i;
|
|
ssize_t j;
|
|
size_t len_s1;
|
|
size_t len_s2;
|
|
|
|
if (s1 == NULL || s2 == NULL)
|
|
return (NULL);
|
|
len_s1 = ft_strlen(s1);
|
|
len_s2 = ft_strlen(s2);
|
|
out = malloc(sizeof(char) * (len_s1 + len_s2 + 1));
|
|
if (out == NULL)
|
|
return (NULL);
|
|
i = -1;
|
|
while (++i < (ssize_t) len_s1)
|
|
out[i] = s1[i];
|
|
j = -1;
|
|
while (++j < (ssize_t) len_s2)
|
|
out[j + i] = s2[j];
|
|
out[i + j] = 0;
|
|
return (out);
|
|
}
|