-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memchr.c
49 lines (41 loc) · 1.52 KB
/
ft_memchr.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edegraev <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/10 22:05:31 by edegraev #+# #+# */
/* Updated: 2023/11/16 11:25:28 by edegraev ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
unsigned char *str;
i = 0;
str = (unsigned char *)s;
while (i < n)
{
if (str[i] == (unsigned char)c)
return (str + i);
i++;
}
return (NULL);
}
// #include <stdio.h>
// #include <stdlib.h>
// int main(void)
// {
// const char *str = "Hello, World!";
// int search_char = 'W';
// size_t n = 13;
// void *result = ft_memchr(str, search_char, n);
// if (result != NULL)
// printf("Caractère trouvé à la position %ld.\n",
// (unsigned char *)result - (unsigned char *)str);
// else
// printf("Caractère non trouvé dans la chaîne.\n");
// return 0;
// }