/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strjoin.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/11/14 21:17:12 by hulamy #+# #+# */ /* Updated: 2019/03/25 15:31:03 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ /* ** create a new string by concatenating the two strings s1 and s2 */ #include "libft.h" static char *ft_doit(char const *s1, char const *s2, char *dest) { int j; int i; j = 0; i = 0; while (s1[j] != '\0') { dest[i] = s1[j]; i++; j++; } j = 0; while (s2[j] != '\0') { dest[i] = s2[j]; i++; j++; } dest[i] = '\0'; return (dest); } char *ft_strjoin(char const *s1, char const *s2) { char *str; if (!s1 || !s2) return (NULL); if (!(str = (char *)malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1)))) return (NULL); str = ft_doit(s1, s2, str); return (str); }