-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memchr.c
39 lines (35 loc) · 1.31 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kakiba <kotto555555@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/12 00:04:15 by kakiba #+# #+# */
/* Updated: 2022/07/25 07:39:24 by kakiba ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *buf;
unsigned char ch;
size_t i;
buf = (unsigned char *)s;
ch = (unsigned char)c;
i = 0;
while (i < n)
{
if (buf[i] == ch)
return ((void *)(buf + i));
i++;
}
return (NULL);
}
// int main(void)
// {
// char str[] = "abcdefghijklmnopqrstu";
// printf("before: %s\n", str);
// printf("%s",(char *)ft_memchr(str, 'e', 50));
// return 0;
// }