ft_strstr, norming ft_strchr, ft_strrchr
This commit is contained in:
parent
c94e1f448e
commit
aa17bb3c11
3
Makefile
3
Makefile
@ -6,7 +6,7 @@
|
||||
# By: tmaze <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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 \
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
32
ft_strstr.c
Normal file
32
ft_strstr.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user