40 lines
1.3 KiB
C
40 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strjoin.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2020/11/24 15:20:38 by pbonilla #+# #+# */
|
|
/* Updated: 2020/11/24 15:52:53 by pbonilla ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strjoin(char const *s1, char const *s2)
|
|
{
|
|
char *new;
|
|
size_t len_s1;
|
|
size_t len_s2;
|
|
size_t i;
|
|
|
|
if (!(s1 && s2))
|
|
return (NULL);
|
|
len_s1 = ft_strlen(s1);
|
|
len_s2 = ft_strlen(s2);
|
|
if (!(new = malloc(sizeof(char *) * (len_s1 + len_s2 + 1))))
|
|
return (NULL);
|
|
i = -1;
|
|
while (s1[++i])
|
|
new[i] = s1[i];
|
|
i = -1;
|
|
while (s2[++i])
|
|
{
|
|
new[len_s1] = s2[i];
|
|
len_s1++;
|
|
}
|
|
new[len_s1] = 0;
|
|
return (new);
|
|
}
|