-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
40 lines (36 loc) · 1.48 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
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jados-sa <jados-sa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/29 19:07:27 by jados-sa #+# #+# */
/* Updated: 2024/10/29 19:51:21 by jados-sa ### ########.fr */
/* */
/* ************************************************************************** */
/* Locate a substring in a string *
* Locates the first occurence of the null-terminated string little in the *
* string big, where not more than len characters are searched. *
* Characters that appear after a \0 character are not searched */
#include "libft.h"
char *ft_strnstr(char *big, char *little, size_t len)
{
size_t i;
size_t j;
char *b;
i = 0;
b = (char *)big;
if (little[0] == '\0')
return (b);
while (i < len && big[i])
{
j = 0;
while (little[j] && (i + j) < len && big[i + j] == little[j])
j++;
if (!little[j])
return (b + i);
i++;
}
return (NULL);
}