-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
46 lines (43 loc) · 1.41 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gudaniel <gudaniel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 13:59:52 by gudaniel #+# #+# */
/* Updated: 2024/04/22 18:34:26 by gudaniel ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(char *origin, char *find, size_t n)
{
size_t i;
size_t j;
i = 0;
if (!n && !origin)
return (NULL);
if (!origin[i] && !find[i])
return (origin);
if (!find[i])
return (origin);
while ((origin[i]))
{
j = 0;
while (origin[i + j] == find[j] && (i + j) < n)
{
if (find[j] == '\0' && origin[i + j] == '\0')
return (origin + i);
j++;
}
if (find[j] == '\0')
return (origin + i);
i++;
}
return (0);
}
/* int main()
{
printf("%s", ft_strnstr("Gustavo", "tavo", 6));
return(0);
} */