-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
31 lines (28 loc) · 1.19 KB
/
ft_strnstr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oelkhiar <oelkhiar@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/11 19:03:46 by oelkhiar #+# #+# */
/* Updated: 2022/10/31 13:54:28 by oelkhiar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *s1, const char *s2, size_t len)
{
size_t len_s2;
len_s2 = ft_strlen(s2);
if (!*s2)
return ((char *)s1);
if (!len)
return (0);
while (*s1 && len-- >= len_s2)
{
if (*s1 == *s2 && ft_memcmp(s1, s2, len_s2) == 0)
return ((char *)s1);
s1++;
}
return (NULL);
}