-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memchr.c
47 lines (40 loc) · 1.4 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hecmarti <hecmarti@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/12 18:09:40 by hecmarti #+# #+# */
/* Updated: 2023/10/18 14:59:44 by hecmarti ### ########.fr */
/* */
/* ************************************************************************** */
#include<stdio.h>
#include<string.h>
void *ft_memchr(const void *str, int c, size_t n)
{
unsigned char *ucstr;
size_t i;
ucstr = (unsigned char *)str;
i = 0;
while (i < n)
{
if (ucstr[i] == (unsigned char)c)
return ((void *)&ucstr[i]);
i++;
}
return (NULL);
}
/*
int main(void)
{
char *str = "Hello, world!";
int c = 'i';
void *result = ft_memchr(str, c, strlen(str));
if (result != NULL)
printf("El byte '%c' fue encontrado.\n", c);
else
printf("El byte '%c' no fue encontrado.\n", c);
return (0);
}
*/