-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
35 lines (32 loc) · 1.26 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
32
33
34
35
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: juhagon <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/04 09:44:02 by juhagon #+# #+# */
/* Updated: 2021/11/09 10:01:22 by juhagon ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *str, const char *to_find, size_t len)
{
size_t c;
int d;
c = 0;
d = 0;
if ((len <= 0 && *to_find == 0) || ((!*str) && *to_find <= 0))
return ((char *)str);
if (!*str)
return (NULL);
c = ft_strlen(to_find);
while (len >= c && *str)
{
if (!(ft_strncmp(str, to_find, c)))
return ((char *)str);
str++;
len--;
}
return (0);
}