37 lines
1.2 KiB
C
37 lines
1.2 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* ft_strjoin.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2015/11/29 09:48:11 by gbrochar #+# #+# */
|
||
|
/* Updated: 2015/12/05 16:25:38 by gbrochar ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
#include "libft.h"
|
||
|
|
||
|
char *ft_strjoin(char const *s1, char const *s2)
|
||
|
{
|
||
|
char *str;
|
||
|
size_t len;
|
||
|
size_t i;
|
||
|
|
||
|
i = 0;
|
||
|
len = ft_strlen(s1) + ft_strlen(s2);
|
||
|
str = (char *)malloc((len + 1) * sizeof(char));
|
||
|
if (!str)
|
||
|
return (NULL);
|
||
|
while (i < len)
|
||
|
{
|
||
|
if (i < ft_strlen(s1))
|
||
|
str[i] = s1[i];
|
||
|
else
|
||
|
str[i] = s2[i - ft_strlen(s1)];
|
||
|
i++;
|
||
|
}
|
||
|
str[i] = '\0';
|
||
|
return (str);
|
||
|
}
|