-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
executable file
·41 lines (38 loc) · 1.36 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmasstou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/03 13:04:02 by mmasstou #+# #+# */
/* Updated: 2021/11/10 18:29:57 by mmasstou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *src, const char *to_find, size_t size)
{
int index;
int jndex;
int psize;
if (*to_find == 0)
return ((char *)src);
jndex = -1 ;
while (src[++jndex] && size != 0)
{
index = 0;
if (src[jndex] == to_find[index])
{
psize = size;
while (src[jndex + index] == to_find[index] && psize != 0)
{
index++;
if (to_find[index] == '\0')
return (&((char *)src)[jndex]);
psize--;
}
}
size--;
}
return (0);
}