/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strjoin.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: thrieg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:14:45 by thrieg #+# #+# */ /* Updated: 2025/02/16 19:04:47 by thrieg ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" //returns NULL if any argument is null or if an allocation fails char *ft_strjoin(char const *s1, char const *s2) { char *ret; int i; int j; if (!s1 || !s2) return (NULL); ret = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1)); if (!ret) return (NULL); i = 0; while (s1[i]) { ret[i] = s1[i]; i++; } j = 0; while (s2[j]) { ret[i] = s2[j]; i++; j++; } ret[i] = '\0'; return (ret); }