-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
61 lines (52 loc) · 1.74 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
56
57
58
59
60
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: julmuntz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/16 13:59:37 by julmuntz #+# #+# */
/* Updated: 2022/05/20 17:12:21 by julmuntz ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *full, const char *part, size_t len)
{
size_t i;
size_t l;
i = 0;
l = 0;
if (*part == 0)
return ((char *)full);
if (*full == 0 && *part == 0)
return ("");
while (full[i] && i < len)
{
while (full[i + l] == part[l] && (i + l < len))
{
l++;
if (part[l] == 0)
return ((char *)full + i);
}
l = 0;
i++;
}
return (NULL);
}
/*
#include <stdio.h>
#include <bsd/string.h>
int main(void)
{
const char *full = "My name is Bond... James Bond";
const char *part = "Bo";
char *ptr;
puts("\n- strnstr");
ptr = strnstr(full, part, 007);
printf("Begins at first %s.\nThe output is: %s.\n", part, ptr);
puts("\n- ft_strnstr");
ptr = ft_strnstr(full, part, 007);
printf("Begins at first %s.\nThe output is: %s.\n", part, ptr);
return (0);
}
*/