-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
33 lines (30 loc) · 1.25 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: younhwan <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/06 18:27:05 by younhwan #+# #+# */
/* Updated: 2022/07/08 18:05:12 by younhwan ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *s, const char *target, size_t n)
{
size_t s_len;
size_t target_len;
if (!(*target))
return ((char *) s);
s_len = ft_strlen(s);
target_len = ft_strlen(target);
if (s_len < target_len || n < target_len)
return (0);
while (target_len <= n--)
{
if (!ft_memcmp(s, target, target_len))
return ((char *) s);
s++;
}
return (0);
}