-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memchr.c
43 lines (37 loc) · 1.35 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
43
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tpouget <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/14 17:04:37 by tpouget #+# #+# */
/* Updated: 2020/05/14 17:06:04 by tpouget ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
unsigned char *data;
unsigned char value;
i = 0;
data = (unsigned char*)s;
value = (unsigned char)c;
while (i < n && data[i] != value)
i++;
return (i == n ? NULL : data + i);
}
/*
#include <unistd.h>
int main(void)
{
char arr[] = "hello world\n";
char* p;
p = ft_memchr(arr, 'w', 0);
if (!p) write(1, "NULL !\n", 7);
p = ft_memchr(arr, 'w', sizeof arr);
write(1, p, 6);
return 0;
}
*/