-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memchr.c
More file actions
31 lines (28 loc) · 1.2 KB
/
ft_memchr.c
File metadata and controls
31 lines (28 loc) · 1.2 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: metaskin <metaskin@student.42istanbul.c +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/31 12:13:55 by metaskin #+# #+# */
/* Updated: 2026/01/19 14:56:00 by metaskin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
const unsigned char *mem_ptr;
unsigned char target_char;
size_t idx;
mem_ptr = (const unsigned char *)s;
target_char = (unsigned char)c;
idx = 0;
while (n--)
{
if (mem_ptr[idx] == target_char)
return ((void *)&mem_ptr[idx]);
idx++;
}
return (0);
}