From 387758be4da61d71e1bc453f7a6317a207c35d14 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Thu, 27 Feb 2020 18:07:14 +0100 Subject: [PATCH] ajout de ft_concat_free --- Makefile | 3 ++- includes/libft.h | 3 ++- srcs/ft_concat_free.c | 53 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 srcs/ft_concat_free.c diff --git a/Makefile b/Makefile index d47cc76..809fdec 100644 --- a/Makefile +++ b/Makefile @@ -94,7 +94,8 @@ SRCS = ft_memset.c \ ft_arraymap.c \ ft_strmultisplit.c \ \ - get_next_line.c + get_next_line.c \ + ft_concat_free.c ODIR = ./builds OBJS = $(SRCS:%.c=$(ODIR)/%.o) diff --git a/includes/libft.h b/includes/libft.h index 0df94b9..893d39a 100644 --- a/includes/libft.h +++ b/includes/libft.h @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/25 14:45:53 by hulamy #+# #+# */ -/* Updated: 2020/02/25 18:43:18 by hulamy ### ########.fr */ +/* Updated: 2020/02/27 18:06:10 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -104,5 +104,6 @@ int *ft_arraymap(int *tab, int length, int(*f)(int)); void ft_putnbrendl(int n); void ft_putnbrendl_fd(int n, int fd); int get_next_line(const int fd, char **line); +char *ft_concat_free(char *str1, char *str2); #endif diff --git a/srcs/ft_concat_free.c b/srcs/ft_concat_free.c new file mode 100644 index 0000000..d31a4cd --- /dev/null +++ b/srcs/ft_concat_free.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_concat_free.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/27 18:04:09 by hulamy #+# #+# */ +/* Updated: 2020/02/27 18:06:44 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** create a new string size of str1 + str2 +** fill it with concated str1 and str2m as "str1str2" +** free the received strings str1 and str2 +** return the new string +*/ + +/* +** #include +** #include "libft.h" +** +** char *ft_concat_free(char *str1, char *str2); +** +** int main(int ac, char **av) +** { +** if (ac != 3) +** return (0); +** printf("%s\n", ft_concat_free(ft_strdup(av[1]), ft_strdup(av[2]))); +** return (0); +** } +*/ + +#include "libft.h" + +char *ft_concat_free(char *str1, char *str2) +{ + char *cat; + int i; + int j; + + cat = ft_memalloc(sizeof(char) * (ft_strlen(str1) + ft_strlen(str2) + 1)); + i = -1; + j = 0; + while (str1[++i]) + cat[i] = str1[i]; + while (str2[j]) + cat[i++] = str2[j++]; + free(str1); + free(str2); + return (cat); +}