From f2f6f951f3a724f8e2c03e2c9ae82bd6b8b50474 Mon Sep 17 00:00:00 2001 From: kinou Date: Tue, 8 Dec 2020 17:52:54 +0100 Subject: [PATCH] =?UTF-8?q?=09nouveau=20fichier=C2=A0:=20ft=5Fstrjoin.c=20?= =?UTF-8?q?=09nouveau=20fichier=C2=A0:=20ft=5Fsubstr.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ft_strjoin.c | 27 +++++++++++++++++++++++++++ ft_substr.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 ft_strjoin.c create mode 100644 ft_substr.c diff --git a/ft_strjoin.c b/ft_strjoin.c new file mode 100644 index 0000000..0f87508 --- /dev/null +++ b/ft_strjoin.c @@ -0,0 +1,27 @@ +char *ft_strjoin(char const *s1, char const *s2) +{ + char *dest; + int i; + int j; + + i = 0; + j = 0; + dest = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1)); + if (dest == 0) + return (0); + while (s1[i]) + { + dest[j] = s1[i]; + j++; + i++; + } + i = 0; + while(s2[i]) + { + dest[j] = s2[i]; + j++; + i++; + } + dest[j] = 0; + return (dest); +} diff --git a/ft_substr.c b/ft_substr.c new file mode 100644 index 0000000..d4533b3 --- /dev/null +++ b/ft_substr.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/11/29 22:54:40 by apommier #+# #+# */ +/* Updated: 2020/11/29 23:28:20 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + char *dest; + int i; + + i = 0; + dest = malloc(sizeof(char) * len); + if (dest == 0) + return (0); + while (len - 1) + { + dest[i] = s[i + start]; + len--; + i++; + } + dest[i] = 0; + return (dest); +}