-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memchr.c
40 lines (36 loc) · 1.46 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smizuoch <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/18 15:05:38 by smizuoch #+# #+# */
/* Updated: 2023/06/07 14:15:54 by smizuoch ### ########.fr */
/* */
/* ************************************************************************** */
#include"libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *str;
c = (unsigned char)c;
str = (unsigned char *)s;
while (n --)
{
if (*str == c)
return (str);
str ++;
}
return (NULL);
}
/* int main(void)
{
printf ("%s\n", memchr("Hello", 'l', 5));
printf ("%s\n", ft_memchr("Hello", 'l', 5));
printf ("%s\n", memchr("Hello", '\0', 5));
printf ("%s\n", ft_memchr("Hello", '\0', 5));
printf ("%s\n", memchr("", 'l', 5));
printf ("%s\n", ft_memchr("", 'l', 5));
printf ("%s\n", memchr("Helloabc", -159, 10));
printf ("%s\n", ft_memchr("Helloabc", -159, 10));
} */