-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_strnstr.c
37 lines (34 loc) · 1.29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sel-mlil <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/23 02:35:23 by sel-mlil #+# #+# */
/* Updated: 2024/11/01 13:56:58 by sel-mlil ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
int ii;
if (!big && !len)
return (NULL);
if (!*little)
return ((char *)big);
i = 0;
while (big[i] && i < len)
{
if (i > len - ft_strlen(little))
break ;
ii = 0;
while (big[i + ii] == little[ii] && little[ii] && i + ii < len)
ii++;
if (!little[ii])
return ((char *)(big + i));
i++;
}
return (NULL);
}