-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memchr.c
38 lines (35 loc) · 1.36 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akdemir <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/09 20:41:54 by akdemir #+# #+# */
/* Updated: 2023/07/14 17:32:46 by akdemir ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
i = 0;
if (!n)
return (NULL);
while (i < n)
{
if (((unsigned char *)s)[i] == (unsigned char)c)
return ((unsigned char *)s + i);
i++;
}
return (NULL);
}
int main()
{
const char str[] = "akif";
int c = 'i';
void *res = ft_memchr(str, c, sizeof(str));
printf("%c", *(char*)res);
return 0;
}
//const void *s -> mande öyle -> char 1 int 4 istediğine -> const void *s = (unsigned char *)s