From 698a37b3999245d6e0ff5b98d25b816be0e7c05a Mon Sep 17 00:00:00 2001 From: Tanguy MAZE Date: Wed, 4 Apr 2018 19:22:29 +0200 Subject: [PATCH] ft_strchr, norming ft_strcpy, ft_strncat, ft_strncpy --- Makefile | 3 ++- ft_strchr.c | 24 ++++++++++++++++++++++++ ft_strcpy.c | 3 +-- ft_strncat.c | 4 ++-- ft_strncpy.c | 5 ++--- 5 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 ft_strchr.c diff --git a/Makefile b/Makefile index fee204a..30b88b5 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: tmaze +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2018/04/04 10:51:59 by tmaze #+# #+# # -# Updated: 2018/04/04 18:34:41 by tmaze ### ########.fr # +# Updated: 2018/04/04 18:59:36 by tmaze ### ########.fr # # # #******************************************************************************# @@ -23,6 +23,7 @@ SRCS = \ ft_strncpy.c \ ft_strcat.c \ ft_strncat.c \ + ft_strchr.c \ ft_isalpha.c \ ft_isdigit.c \ ft_isalnum.c \ diff --git a/ft_strchr.c b/ft_strchr.c new file mode 100644 index 0000000..d90ce03 --- /dev/null +++ b/ft_strchr.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaze +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/04/04 18:54:17 by tmaze #+# #+# */ +/* Updated: 2018/04/04 19:15:12 by tmaze ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strchr(const char *s, int c) +{ + int i; + + i = -1; + while (++i == 0 || s[i - 1]) + if (s[i] == c) + return (strdup(&s[i])); + return (NULL); +} diff --git a/ft_strcpy.c b/ft_strcpy.c index 1e022cc..6ffa032 100644 --- a/ft_strcpy.c +++ b/ft_strcpy.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/04 16:15:42 by tmaze #+# #+# */ -/* Updated: 2018/04/04 16:39:29 by tmaze ### ########.fr */ +/* Updated: 2018/04/04 19:19:41 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,4 +21,3 @@ char *ft_strcpy(char *dest, const char *src) dest[i] = src[i]; return (dest); } - diff --git a/ft_strncat.c b/ft_strncat.c index 23de45b..310afee 100644 --- a/ft_strncat.c +++ b/ft_strncat.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/04 18:29:06 by tmaze #+# #+# */ -/* Updated: 2018/04/04 18:34:17 by tmaze ### ########.fr */ +/* Updated: 2018/04/04 19:20:04 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ char *ft_strncat(char *restrict dest, const char *src, size_t n) { int dest_len; - + dest_len = ft_strlen(dest); ft_strncpy(&dest[dest_len], src, n); return (dest); diff --git a/ft_strncpy.c b/ft_strncpy.c index faade39..4ec31dd 100644 --- a/ft_strncpy.c +++ b/ft_strncpy.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/04 16:55:29 by tmaze #+# #+# */ -/* Updated: 2018/04/04 17:14:03 by tmaze ### ########.fr */ +/* Updated: 2018/04/04 19:21:06 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,10 +17,9 @@ char *ft_strncpy(char *dest, const char *src, size_t n) unsigned int i; i = -1; - while (++i < n && ( i == 0 || src[i - 1])) + while (++i < n && (i == 0 || src[i - 1])) dest[i] = src[i]; while (++i < n) dest[i] = '\0'; return (dest); } -