From a60d17a0b9f36f007905508008c6a809edb51ed9 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sat, 10 Dec 2016 18:25:36 +0100 Subject: [PATCH] sstrcat --- libftasm/includes/libft.h | 3 ++- libftasm/src/ft_printf/ft_printf.c | 2 +- libftasm/src/ft_printf/ft_transform.c | 2 +- libftasm/src/sstr/ft_sstrcat.c | 37 +++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 libftasm/src/sstr/ft_sstrcat.c diff --git a/libftasm/includes/libft.h b/libftasm/includes/libft.h index 0a9f831d..8877379d 100644 --- a/libftasm/includes/libft.h +++ b/libftasm/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2016/12/09 22:11:49 by jhalford ### ########.fr */ +/* Updated: 2016/12/10 17:02:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -145,6 +145,7 @@ void ft_sstrprint_fd(int fd, char **list, char sep); char **ft_sstrdup(char **list); void ft_sstrdel(char **sstr, int index); void ft_sstrfree(char **sstr); +char *ft_sstrcat(char **sstr, char sep); char *ft_path_notdir(char *path); diff --git a/libftasm/src/ft_printf/ft_printf.c b/libftasm/src/ft_printf/ft_printf.c index 61f98fc5..9c9c69ea 100644 --- a/libftasm/src/ft_printf/ft_printf.c +++ b/libftasm/src/ft_printf/ft_printf.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ -/* Updated: 2016/12/09 22:10:32 by jhalford ### ########.fr */ +/* Updated: 2016/12/10 16:50:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/ft_printf/ft_transform.c b/libftasm/src/ft_printf/ft_transform.c index 8aea5e1e..f8115517 100644 --- a/libftasm/src/ft_printf/ft_transform.c +++ b/libftasm/src/ft_printf/ft_transform.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */ -/* Updated: 2016/12/09 19:13:57 by jhalford ### ########.fr */ +/* Updated: 2016/12/10 16:51:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/sstr/ft_sstrcat.c b/libftasm/src/sstr/ft_sstrcat.c new file mode 100644 index 00000000..d0256754 --- /dev/null +++ b/libftasm/src/sstr/ft_sstrcat.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sstrcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/10 16:58:06 by jhalford #+# #+# */ +/* Updated: 2016/12/10 17:03:27 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_sstrcat(char **sstr, char sep) +{ + int len; + int i; + char *out; + + i = 0; + len = 0; + if (!sstr) + return (NULL); + while (sstr[i]) + len += ft_strlen(sstr[i++]); + if (!(out = ft_strnew(sizeof(char) * (len + i + 1)))) + return (NULL); + ft_strcat(out, sstr[0]); + i = 1; + while (sstr[i]) + { + ft_strcat(out, (char[]){sep, 0}); + ft_strcat(out, sstr[i]); + } + return (out); +}