-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
36 lines (33 loc) · 1.33 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jovicto2 <jovicto2@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/16 18:47:40 by jovicto2 #+# #+# */
/* Updated: 2023/05/16 18:48:32 by jovicto2 ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
char *first_occurrence;
size_t i;
size_t l_len;
first_occurrence = NULL;
i = 0;
l_len = ft_strlen(little);
while (big[i] && i < len && l_len)
{
if (!ft_strncmp((big + i), little, l_len) && (i + l_len <= len))
{
first_occurrence = (char *)(big + i);
break ;
}
i++;
}
if (!l_len)
first_occurrence = (char *)big;
return (first_occurrence);
}