blob: 5f4bb91d88ac4b2c4b5f892c2cfb098cf566f01f (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:25:13 by cacharle #+# #+# */
/* Updated: 2019/10/07 10:26:11 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <string.h>
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
size_t j;
size_t little_len;
little_len = ft_strlen(little);
if (little_len == 0 || len == 0)
return ((char*)big);
i = 0;
while (i < len && big[i])
{
j = 0;
while (i + j < len && little[j] && big[i + j])
{
if (little[j] != big[i + j])
break ;
j++;
}
if (j == little_len)
return ((char*)big + i);
i++;
}
return (NULL);
}
|