-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strnstr.c
More file actions
42 lines (37 loc) · 1.37 KB
/
ft_strnstr.c
File metadata and controls
42 lines (37 loc) · 1.37 KB
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: aabduvak <abdulaziz.yosk@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/30 01:53:19 by aabduvak #+# #+# */
/* Updated: 2021/12/30 01:53:19 by aabduvak ### ########.fr */
/* */
/* ************************************************************************** */
/*
haystack -> samanlık
needle -> iğne
samanlıkta iğne aramak :)
*/
#include "libft.h"
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
size_t index;
size_t jndex;
jndex = 0;
if (!*needle)
return ((char *)haystack);
while (*haystack && jndex < len)
{
index = 0;
while (needle[index] && haystack[index] == needle[index]
&& ((jndex + index) < len))
index++;
if (!needle[index])
return ((char *)haystack);
jndex++;
haystack++;
}
return (0);
}