-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memchr.c
34 lines (30 loc) · 1.23 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ldel-val <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/24 11:42:54 by ldel-val #+# #+# */
/* Updated: 2024/10/10 19:46:23 by ldel-val ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *match;
match = (unsigned char *)s;
while (n--)
if (*match++ == (unsigned char)c)
return (match - 1);
return (NULL);
}
/*
int main(void)
{
char s[] = "Hello world";
char c = '\0';
printf("ft: %s\noriginal: %s", (char *)ft_memchr(s, c, 11),
(char *)memchr(s, c, 11));
}
*/