-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
56 lines (51 loc) · 1.72 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edegraev <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 15:07:44 by edegraev #+# #+# */
/* Updated: 2023/11/16 14:43:09 by edegraev ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
size_t j;
if ((!big || !little) && len == 0)
return (NULL);
i = 0;
if (!*little)
return ((char *)big);
while (big[i] && i < len)
{
j = 0;
while (big[i + j] == little[j] && (i + j) < len)
{
if (little[j + 1] == '\0')
return ((char *)&big[i]);
j++;
}
i++;
}
return (NULL);
}
// #include <stdio.h>
// // #include <string.h>
// // #include <stdlib.h>
// #include <string.h>
// int main()
// {
// // char *str = "Salut les amis";
// // char *to_find = "les";
// char *result;
// //result = strnstr(str, to_find, 5);
// //printf("%s\n", result);
// // result = ft_strnstr(str, to_find, 10);
// // printf("%s\n", result);
// result = ft_strnstr("lorem ipsum dolor sit amet", "", 10);
// printf("%s\n", result);
// return (0);
// }