-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_memchr.c
42 lines (37 loc) · 1.43 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/25 21:57:14 by mcombeau #+# #+# */
/* Updated: 2021/12/03 16:31:15 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
DESCRIPTION :
The function ft_memchr searches n bytes of the memory area pointed to
by s for the first occurence of c. Both c and the bytes of s are
interpreted as unsigned char.
RETURN VALUE:
A pointer to the matching byte. NULL if the character does not occur
in the given memory area.
*/
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
unsigned char ch;
const unsigned char *str;
ch = c;
str = (const unsigned char *)s;
i = 0;
while (i < n)
{
if (str[i] == ch)
return ((void *)s + i);
i++;
}
return (0);
}