-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
38 lines (35 loc) · 1.33 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbaypara <mbaypara@student.42kocaeli.co +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/06 17:55:20 by mbaypara #+# #+# */
/* Updated: 2023/12/12 15:11:19 by mbaypara ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
size_t i;
size_t c;
size_t n_len;
char *hay;
i = 0;
hay = (char *)haystack;
n_len = ft_strlen(needle);
if (n_len == 0 || haystack == needle)
return (hay);
while (hay[i] != '\0' && i < len)
{
c = 0;
while (hay[i + c] != '\0' && needle[c] != '\0'
&& hay[i + c] == needle[c] && i + c < len)
c++;
if (c == n_len)
return (hay + i);
i++;
}
return (0);
}