-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strnstr.c
More file actions
49 lines (44 loc) · 1.45 KB
/
ft_strnstr.c
File metadata and controls
49 lines (44 loc) · 1.45 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
39
40
41
42
43
44
45
46
47
48
49
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thfranco <thfranco@student.42.rio> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 11:29:36 by thfranco #+# #+# */
/* Updated: 2023/11/04 11:29:37 by thfranco ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *str, const char *find, size_t n)
{
size_t i;
size_t j;
i = 0;
if (find[i] == '\0' || find == NULL)
return ((char *)str);
while (str[i] != '\0' && i < n)
{
j = 0;
while (find[j] == str[i + j] && i + j < n)
{
if (find[j + 1] == '\0')
{
return ((char *)str + i);
}
j++;
}
i++;
}
return (NULL);
}
/*int main()
{
const char *big = "AEFBDEFABCDEF";
const char *little = "EFA";
size_t len = 8;
char *t;
t = ft_strnstr(big, little, len);
printf("Resutl: %s\n", t);
return 0;
}*/