-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
31 lines (28 loc) · 1.2 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mohkhald <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 23:50:24 by mohkhald #+# #+# */
/* Updated: 2024/11/20 08:32:05 by mohkhald ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *src, const char *target, size_t n)
{
size_t n_len;
n_len = ft_strlen(target);
if (!n_len)
return ((char *)src);
if (!src && n == 0)
return (NULL);
while (*src && n-- >= n_len)
{
if (!ft_strncmp(src, target, n_len))
return ((char *)src);
src++;
}
return (NULL);
}