-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memchr.c
37 lines (33 loc) · 1.45 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dalves-p <dalves-p@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/27 16:34:15 by dalves-p #+# #+# */
/* Updated: 2021/06/29 11:26:55 by dalves-p ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** LIBRARY: <strings.h>
** DESCRIPTION:
** The memchr() function scans the initial n bytes of the memory area pointed
** to by s for the first instance of c. Both c and the bytes of the memory area
** pointed to by s are interpreted as unsigned char.
** It return a pointer to the matching byte or 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;
i = 0;
while (i < n)
{
if (*((unsigned char *)(s + i)) == (unsigned char)c)
return ((void *)(s + i));
i++;
}
return (0);
}