-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strnstr.c
More file actions
45 lines (42 loc) · 1.48 KB
/
ft_strnstr.c
File metadata and controls
45 lines (42 loc) · 1.48 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pabad-ap <pabad-ap@student.42barcel> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/29 17:09:15 by pabad-ap #+# #+# */
/* Updated: 2023/09/30 00:19:43 by pabad-ap ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
size_t i;
size_t c;
i = 0;
if (needle[i] == '\0')
return ((char *)haystack);
while ((i < len) && (haystack[i] != '\0'))
{
c = 0;
while (haystack[i + c] != '\0' && needle[c] != '\0' \
&& haystack[i + c] == needle[c] \
&& (i + c) < len)
c ++;
if (ft_strlen(needle) == c)
return ((char *)(haystack + i));
i ++;
}
return (NULL);
}
/*
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
if (argc == 4)
printf("%s",ft_strnstr(argv[1], argv[2], atoi(argv[3])));
return (0);
}
*/