-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strnstr.c
More file actions
46 lines (42 loc) · 1.4 KB
/
Copy pathft_strnstr.c
File metadata and controls
46 lines (42 loc) · 1.4 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
43
44
45
46
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jihyjeon < jihyjeon@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/11 13:51:32 by jihyjeon #+# #+# */
/* Updated: 2023/11/07 17:48:02 by jihyjeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_min(size_t a, size_t b)
{
if (a <= b)
return (a);
return (b);
}
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
size_t i;
size_t uphere;
char *hays;
hays = (char *)haystack;
uphere = ft_min(len, ft_strlen(haystack)) - ft_strlen(needle) + 1;
if (needle[0] == '\0')
return (hays);
if (!len)
return (0);
while (*hays && uphere--)
{
i = 0;
while (*(hays + i) == *(needle + i))
{
i++;
if (*(needle + i) == '\0')
return (hays);
}
hays++;
}
return (0);
}