-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strnstr.c
More file actions
44 lines (41 loc) · 1.47 KB
/
ft_strnstr.c
File metadata and controls
44 lines (41 loc) · 1.47 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jowagner <jowagner@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/12 14:03:04 by jowagner #+# #+# */
/* Updated: 2024/12/12 19:50:22 by jowagner ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @brief Locates a substring within a string, limited to a specified length.
*
* @param haystack The string to search in.
* @param needle The substring to search for.
* @return Pointer to the first occurrence of needle in haystack,
* or NULL if not found.
*/
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
size_t j;
i = 0;
j = 0;
if (!little[j])
return ((char *)big);
while (big[i] && len > i)
{
while (little[j] == big[i + j] && len > (i + j))
{
j++;
if (!little[j])
return ((char *)big + i);
}
i++;
j = 0;
}
return (0);
}