-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memchr.c
35 lines (31 loc) · 1.37 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_memchr.c :+: :+: */
/* +:+ */
/* By: jaberkro <[email protected]> +#+ */
/* +#+ */
/* Created: 2021/10/22 11:38:26 by jaberkro #+# #+# */
/* Updated: 2021/10/22 15:04:53 by jaberkro ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *input;
size_t counter;
counter = 0;
input = (unsigned char *)s;
while (counter < n)
{
if (input[counter] == (unsigned char)c)
return ((void *)(input + counter));
counter++;
}
return (0);
}
/* The memchr() function locates the first occurrence of c
(converted to an unsigned char) in string s.
The memchr() function returns a pointer to the byte
located, or NULL if no such byte exists within n bytes.
*/