-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
37 lines (34 loc) · 1.29 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
36
37
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dbrophy <dbrophy@student.42.us.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/19 00:00:41 by dbrophy #+# #+# */
/* Updated: 2020/02/19 00:00:41 by dbrophy ### ########.fr */
/* */
/* ************************************************************************** */
#include "stdlib.h"
#include "string.h"
#include "libft.h"
char *ft_strnstr(const char *str, const char *to_find, size_t len)
{
int i;
size_t j;
if (str == NULL || to_find == NULL)
return (NULL);
j = ft_strlen(to_find) - 1;
if (*to_find == 0)
return ((char*)str);
while (*str && j < len)
{
i = 0;
while (str[i] == to_find[i])
if (to_find[++i] == 0)
return ((char*)str);
str++;
j++;
}
return (NULL);
}