-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strnstr.c
More file actions
77 lines (72 loc) · 2.4 KB
/
Copy pathft_strnstr.c
File metadata and controls
77 lines (72 loc) · 2.4 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
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: nepcohen <nepcohen@learner.42.tech> /#/ /#/ */
/* /#/____ |#| /| */
/* Created: 2026/05/31 18:37:23 by nepcohen |#######| |#|/#| */
/* Updated: 2026/06/01 23:58:48 by nepcohen |#| NEPH_ */
/* */
/* ************************************************************************** */
#include <stddef.h>
/* PROG ==================================================================== */
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t count;
size_t slot;
count = 0;
if (*little == '\0')
return ((char *)big);
if (!len)
return (NULL);
else
{
while (big[count] != '\0' && count < len)
{
slot = 0;
while (big[count + slot] == little[slot]
&& little[slot] != '\0'
&& count + slot < len)
slot++;
if (little[slot] == '\0')
return ((char *)&big[count]);
count++;
}
return (NULL);
}
}
/* MAIN ===================================================================== */
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
void display(const char *playB, const char *playL, size_t playN)
{
const char *result;
printf("Big : `%s`\n", playB);
printf("Little : `%s`\n", playL);
printf("Taille : `%zu`\n", playN);
result = ft_strnstr(playB, playL, playN);
if (result == NULL)
printf("NULL\n");
else if (result == playB)
printf("Little vide : `%s`\n", result);
else
{
printf("Chaine : `%s`\n", result);
printf("Pointer : `%p`\n", (void *)result);
}
}
int main(int argc, char **argv)
{
if (argc != 4)
printf("Merci de saisir les 3 arguments du main");
else
{
display(argv[1], argv[2], atoi(argv[3]));
}
return (0);
}
/* ========================================================================== */
/* END ============================================================= 42_ ==== */
/* ================================================================= NEPHCODE */