-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
55 lines (49 loc) · 1.6 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nmattera <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/06 14:41:37 by nmattera #+# #+# */
/* Updated: 2022/05/16 20:17:20 by nmattera ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
size_t count;
char *bigi;
char *litte;
bigi = (char *) big;
litte = (char *) little;
if (!ft_strlen(litte))
return (bigi);
count = 0;
while (*bigi)
{
i = 0;
while (litte[i] == bigi[i] && litte[i])
i++;
if ((i + count) > len)
return (NULL);
if (i == ft_strlen(litte) && len >= ft_strlen(litte))
return (bigi);
bigi++;
count++;
}
return (NULL);
}
/*
#include <stdio.h>
#include <string.h>
int main()
{
char haystack[30] = "aaabcabcd";
char needle[10] = "aabc";
char * empty = (char*)"";
//printf("OG : %s", source("bimcocoricobim", "cocorico", 12));
printf("pure : %s", ft_strnstr(haystack, "aaabc", 5));
}
*/