-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
37 lines (34 loc) · 1.28 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: sbin-jef <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/28 15:19:51 by sbin-jef #+# #+# */
/* Updated: 2024/08/12 03:13:43 by sbin-jef ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include <stddef.h>
#include "libft.h"
const char *ft_strnstr(const char *str, const char *to_find, size_t n)
{
size_t x;
size_t y;
if (str == NULL)
return (NULL);
if (*to_find == '\0')
return (str);
x = 0;
while (str[x] && x < n)
{
y = 0;
while (str[x + y] == to_find[y] && to_find[y] && (x + y) < n)
y++;
if (to_find[y] == '\0')
return (&str[x]);
x++;
}
return (NULL);
}