-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memchr.c
39 lines (36 loc) · 1.27 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: thuy-ngu <thuy-ngu@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 21:22:25 by thuy-ngu #+# #+# */
/* Updated: 2023/10/13 19:27:54 by thuy-ngu ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *s2;
unsigned char c2;
s2 = (unsigned char *)s;
c2 = (unsigned char)c;
while (n--)
{
if (*s2 == c2)
{
return (s2);
}
s2++;
}
return (NULL);
}
/*int main()
{
const char s[] = "something";
int c = 't';
size_t n = sizeof(s);
const void *result = ft_memchr(s, c, n);
printf("%s", (char *)result);
}*/