/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strjoin.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cchauvet int ft_strlen(char *str) { int i; i = 0; while (str[i] != 0) i++; return (i); } char *ft_strcat(char *dest, char *src) { int i; int j; j = 0; i = 0; while (dest[i] != 0) i++; while (src[j] != 0) { dest[i + j] = src[j]; j++; } dest[i + j] = 0; return (dest); } char *ft_strjoin(int size, char **strs, char *sep) { int i; int word_counter; char *out; if (size == 0) { out = malloc(sizeof(*out)); out = ""; return (out); } i = -1; while (++i < size) { word_counter += ft_strlen(strs[i]); word_counter += ft_strlen(sep); } out = malloc(sizeof(*out) * word_counter); i = 0; while (i < size) { ft_strcat(out, strs[i++]); if (i < size) ft_strcat(out, sep); } return (out); }