-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strnstr.c
More file actions
35 lines (32 loc) · 1.2 KB
/
Copy pathft_strnstr.c
File metadata and controls
35 lines (32 loc) · 1.2 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: user <user@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/29 15:30:00 by user #+# #+# */
/* Updated: 2023/04/29 15:30:00 by user ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *s1, const char *s2, size_t n)
{
size_t i;
size_t j;
if (!s2[0])
return ((char *)s1);
i = 0;
while (s1[i] && i < n)
{
j = 0;
while (s1[i + j] == s2[j] && s1[i + j] && s2[j] && i + j < n)
{
if (!s2[j + 1])
return ((char *)&s1[i]);
j++;
}
i++;
}
return (NULL);
}