-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
42 lines (39 loc) · 1.37 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
38
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vstockma <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 08:37:07 by vstockma #+# #+# */
/* Updated: 2022/10/04 08:37:11 by vstockma ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
size_t j;
size_t strlen;
char *hay;
char *needle;
i = 0;
hay = (char *)big;
needle = (char *)little;
strlen = ft_strlen(needle);
if (strlen == 0 || big == needle)
return (hay);
if (len == 0)
return (NULL);
while (hay[i] && i < len)
{
j = 0;
while (hay[i + j] && needle[j] && hay[i + j] == needle[j]
&& i + j < len)
j++;
if (j == strlen)
return (hay + i);
i++;
}
return (0);
}