-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memchr.c
46 lines (40 loc) · 1.36 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: snocita <snocita@student.42wolfsburg.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/17 14:55:56 by snocita #+# #+# */
/* Updated: 2023/01/07 12:24:11 by snocita ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
// #include <stdio.h>
/*
Locates the first occurence of a character inside a string
*/
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
unsigned char *byte;
unsigned char character;
byte = (unsigned char *)s;
character = (unsigned char)c;
i = 0;
while (i < n)
{
if (*byte == character)
{
return (byte);
}
byte++;
i++;
}
return (NULL);
}
// int main(void)
// {
// char str[] = "HELLOOOO";
// printf("%d", ft_memchr(str, 'H', 2));
// }