diff --git a/Makefile b/Makefile index 5fffd3d..4e68d96 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: tmaze +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2018/04/04 10:51:59 by tmaze #+# #+# # -# Updated: 2018/04/05 10:41:34 by tmaze ### ########.fr # +# Updated: 2018/04/05 11:06:04 by tmaze ### ########.fr # # # #******************************************************************************# @@ -25,6 +25,7 @@ SRCS = \ ft_strncat.c \ ft_strchr.c \ ft_strrchr.c \ + ft_strstr.c \ ft_isalpha.c \ ft_isdigit.c \ ft_isalnum.c \ diff --git a/ft_strchr.c b/ft_strchr.c index 1ba8912..87cae42 100644 --- a/ft_strchr.c +++ b/ft_strchr.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/04 18:54:17 by tmaze #+# #+# */ -/* Updated: 2018/04/05 10:25:13 by tmaze ### ########.fr */ +/* Updated: 2018/04/05 11:05:16 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,8 @@ char *ft_strchr(const char *s, int c) { - int i; - char *tmp; + int i; + char *tmp; i = -1; tmp = (char*)s; diff --git a/ft_strrchr.c b/ft_strrchr.c index c52eeb4..8d357ae 100644 --- a/ft_strrchr.c +++ b/ft_strrchr.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/05 10:40:13 by tmaze #+# #+# */ -/* Updated: 2018/04/05 10:41:19 by tmaze ### ########.fr */ +/* Updated: 2018/04/05 11:05:31 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,9 +14,9 @@ char *ft_strrchr(const char *s, int c) { - int i; - char *tmp; - char *ret; + int i; + char *tmp; + char *ret; i = -1; ret = NULL; diff --git a/ft_strstr.c b/ft_strstr.c new file mode 100644 index 0000000..f675e23 --- /dev/null +++ b/ft_strstr.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaze +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/04/05 10:54:41 by tmaze #+# #+# */ +/* Updated: 2018/04/05 11:19:02 by tmaze ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strstr(const char *haystack, const char *needle) +{ + int i; + int j; + char *tmp; + + i = -1; + tmp = (char*)haystack; + while (++i == 0 || tmp[i - 1]) + if (tmp[i] == needle[0] && (j = 1)) + { + while (tmp[i + j] == needle[j] && needle[j] && tmp[i + j]) + j++; + if (needle[j] == '\0') + return (&tmp[i]); + } + return (NULL); +}