-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memchr.c
49 lines (44 loc) · 1.56 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
44
45
46
47
48
49
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yuske <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/24 16:18:55 by yfurutat #+# #+# */
/* Updated: 2022/11/23 10:56:46 by yuske ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//castをreturnでしなくて済むように、constを外しました。
// void *ft_memchr(const void *str, int ch, size_t n)
// {
// unsigned char *str_caster;
// unsigned char chr;
// size_t i;
// str_caster = (unsigned char *)str;
// chr = (unsigned char)ch;
// i = 0;
// while (i++ < n)
// {
// if (*str_caster == chr)
// return (str_caster);
// str_caster++;
// }
// return (NULL);
// }
//12L
void *ft_memchr(const void *mem, int ch, size_t n)
{
unsigned char *str_caster;
size_t i;
str_caster = (unsigned char *)mem;
i = 0;
while (i++ < n)
{
if (*str_caster == (unsigned char)ch)
return (str_caster);
str_caster++;
}
return (NULL);
}