-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnstr.c
77 lines (64 loc) · 1.97 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hecmarti <hecmarti@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/28 19:51:11 by hecmarti #+# #+# */
/* Updated: 2023/08/21 11:49:46 by hecmarti ### ########.fr */
/* */
/* ************************************************************************** */
#include<stdio.h>
#include"libft.h"
#include<string.h>
#include <stddef.h>
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
size_t i;
size_t j;
if (*needle == '\0')
return ((char *)haystack);
i = 0;
while (haystack[i] && i < len)
{
j = 0;
while (haystack[i + j] == needle[j] && (i + j) < len)
{
if (needle[j + 1] == '\0')
return ((char *)&haystack[i]);
j++;
}
i++;
}
return (NULL);
}
/*
int main(void)
{
const char *haystack = "Hello, world! This is a test string.";
const char *needle = "world";
size_t len = 30;
char *result = ft_strnstr(haystack, needle, len);
if (result != NULL)
printf("Subcadena encontrada en la posición: %ld\n", result - haystack);
else
printf("Subcadena no encontrada.\n");
return 0;
}
TODO
TOFIX
extensiones -chrome.
consent-o-matic
add blocker
Usage of data structures it is a must ! asap !
typedef struct s_type
{
void *ptr;
int number;
} t_type;
variable static it's not the same as static function !!
static size_t ft_strlen(size_t num, char *s)
// can be called only inside same .c
.h heder with
*/