-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memchr.c
48 lines (43 loc) · 1.53 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbin-jef <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/28 15:15:54 by sbin-jef #+# #+# */
/* Updated: 2024/08/12 03:29:29 by sbin-jef ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include "libft.h"
/*#include <stdio.h>*/
void *ft_memchr(const void *str, int c, size_t n)
{
const unsigned char *ptr;
unsigned char chck;
if (!str)
return (NULL);
ptr = (const unsigned char *)str;
chck = (unsigned char)c;
while (n-- > 0)
{
if (*ptr == chck)
return ((void *)ptr);
ptr++;
}
return (NULL);
}
/*
int main() {
char data[] = "Hello, world!";
char target = 'w';
char *result = ft_memchr(data, sizeof(data), target);
if (result) {
printf("Character '%c' found at position: %ld\n", target, result - data);
} else {
printf("Character '%c' not found.\n", target);
}
return 0;
}
*/