ft_strnstr
This commit is contained in:
parent
aa17bb3c11
commit
e50dcca5e8
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 11:06:04 by tmaze ### ########.fr #
|
||||
# Updated: 2018/04/05 11:40:07 by tmaze ### ########.fr #
|
||||
# #
|
||||
#******************************************************************************#
|
||||
|
||||
@ -26,6 +26,7 @@ SRCS = \
|
||||
ft_strchr.c \
|
||||
ft_strrchr.c \
|
||||
ft_strstr.c \
|
||||
ft_strnstr.c \
|
||||
ft_isalpha.c \
|
||||
ft_isdigit.c \
|
||||
ft_isalnum.c \
|
||||
|
33
ft_strnstr.c
Normal file
33
ft_strnstr.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/04/05 11:35:03 by tmaze #+# #+# */
|
||||
/* Updated: 2018/04/05 11:47:18 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char *tmp;
|
||||
|
||||
i = -1;
|
||||
tmp = (char*)haystack;
|
||||
while ((++i == 0 || tmp[i - 1]) && i < (int)len)
|
||||
if (tmp[i] == needle[0] && (j = 1))
|
||||
{
|
||||
while (tmp[i + j] == needle[j] && needle[j] && tmp[i + j]\
|
||||
&& (i + j) < (int)len)
|
||||
j++;
|
||||
if (needle[j] == '\0')
|
||||
return (&tmp[i]);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
4
libft.h
4
libft.h
@ -6,7 +6,7 @@
|
||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/04/04 10:40:01 by tmaze #+# #+# */
|
||||
/* Updated: 2018/04/04 18:08:25 by tmaze ### ########.fr */
|
||||
/* Updated: 2018/04/05 11:39:51 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -37,7 +37,7 @@ size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||
char *ft_strchr(const char *s, int c);
|
||||
char *ft_strrchr(const char *s, int c);
|
||||
char *ft_strstr(const char *haystack, const char *needle);
|
||||
char *ft_strnstr(const char *haystack, const char *needle, size_t n);
|
||||
char *ft_strnstr(const char *haystack, const char *needle, size_t len);
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
int ft_strncmp(const char *s1, const char *s2);
|
||||
int ft_atoi(const char *nptr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user