42_minishell/libftx/extra/ft_strmerger.c

34 lines
1.2 KiB
C
Raw Normal View History

2023-01-31 08:40:15 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmerger.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 15:09:15 by cchauvet #+# #+# */
/* Updated: 2023/01/04 15:24:17 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "extra.h"
char *ft_strmerger(size_t arg_len, ...)
{
va_list va;
char *out;
char *temp;
va_start(va, arg_len);
out = ft_strjoin(va_arg(va, char *), va_arg(va, char *));
while (arg_len > 2)
{
temp = ft_strjoin(out, va_arg(va, char *));
free(out);
if (temp == NULL)
return (NULL);
out = temp;
arg_len--;
}
return (out);
}