-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memchr.c
45 lines (40 loc) · 1.38 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gusgonza <gusgonza@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/31 17:34:19 by gusgonza #+# #+# */
/* Updated: 2024/06/15 01:07:14 by gusgonza ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *str, int c, size_t n)
{
size_t pos;
pos = 0;
while (pos < n)
{
if (((unsigned char *)str)[pos] == (unsigned char)c)
return (&((unsigned char *)str)[pos]);
pos++;
}
return (NULL);
}
/*
// For testing
#include <stdio.h>
int main(void)
{
char str[] = "Hello, World";
int c = 'a';
char *found;
found = (char *)ft_memchr(str, c, sizeof(str));
if (found)
printf("'%c' found -> '%s'\n", c, found);
else
printf("'%c' NOT found\n", c);
return (0);
}
*/