-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memchr.c
More file actions
41 lines (34 loc) · 1.34 KB
/
ft_memchr.c
File metadata and controls
41 lines (34 loc) · 1.34 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
32
33
34
35
36
37
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mraineri <mraineri@student.42lisboa.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/20 17:37:05 by mraineri #+# #+# */
/* Updated: 2024/05/21 15:27:05 by mraineri ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
unsigned char *ptr;
ptr = (unsigned char *)s;
i = 0;
while (i < n)
{
if (((unsigned char *)s)[i] == (unsigned char)c)
return ((unsigned char *)&ptr[i]);
i++;
}
return (NULL);
}
//int main () {
// char s[] = {0, 1, 2 ,3 ,4 ,5};
// const char ch = 'n';
// char *ret;
// ret = ft_memchr(str, ch, 2);
// printf("String after |%c| is - |%s|\n", ch, ret);
// return(0);
//}