-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strnstr.c
More file actions
38 lines (35 loc) · 1.35 KB
/
Copy pathft_strnstr.c
File metadata and controls
38 lines (35 loc) · 1.35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cpoulain <cpoulain@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 12:00:27 by cpoulain #+# #+# */
/* Updated: 2024/10/16 12:17:15 by cpoulain ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
size_t k;
char *big_cpy;
size_t little_len;
little_len = ft_strlen(little);
big_cpy = (char *)big;
if (little_len < 1 || big == little)
return (big_cpy);
i = 0;
while (big[i] && i < len)
{
k = 0;
while (big_cpy[i + k] == little[k] && i + k < len && big_cpy[i + k]
&& little[k])
k++;
if (k == little_len)
return (&big_cpy[i]);
i++;
}
return ((char *) NULL);
}