-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strnstr.c
43 lines (38 loc) · 1.49 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: xle-boul <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/03 00:46:59 by xle-boul #+# #+# */
/* Updated: 2021/10/17 16:23:44 by xle-boul ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* find the first occurence of the string little in the big one
returns the remaining part of the string if successful
returns NULL if not */
char *ft_strnstr(const char *big, const char *little, size_t len)
{
if (*little == '\0')
return ((char *)big);
while (len-- >= ft_strlen(little) && *big != '\0')
{
if (*big == *little && ft_strncmp(big, little, ft_strlen(little)) == 0)
return ((char *)big);
big++;
}
return (NULL);
}
/*
int main()
{
char s[] = "salut tu vas bien";
char c[] = "ut";
int a = 3;
printf("%s\n", strnstr(s, c, a));
printf("%s\n", ft_strnstr(s, c, a));
return 0;
}
*/