-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
41 lines (38 loc) · 1.4 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pmaryjo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/05 18:42:06 by pmaryjo #+# #+# */
/* Updated: 2021/09/05 18:42:07 by pmaryjo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
size_t substr_size;
size_t counter;
char *big;
char *smol;
big = (char *)haystack;
smol = (char *)needle;
counter = 0;
substr_size = ft_strlen(smol);
if (substr_size == 0)
return (big);
if (big[0] == '\0')
return (NULL);
while (len >= substr_size && big[counter])
{
if (big[counter] == *smol
&& ft_strncmp(smol, big + counter, substr_size) == 0)
{
return (big + counter);
}
counter++;
len--;
}
return (NULL);
}