-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
39 lines (36 loc) · 1.36 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nle-roux <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 17:25:16 by nle-roux #+# #+# */
/* Updated: 2023/11/11 15:16:25 by nle-roux ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_strnsub(const char *sub, const char *little)
{
while (*little)
if (*little++ != *sub++)
return (0);
return (1);
}
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t l_len;
l_len = ft_strlen(little);
if (!big && !len)
return (NULL);
if (!*little)
return ((char *)big);
while (*big && len > 0 && l_len <= len)
{
if ((*big == *little) && ft_strnsub(big, little))
return ((char *)big);
big++;
len--;
}
return (NULL);
}