-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memchr.c
56 lines (47 loc) · 1.59 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
49
50
51
52
53
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: julmuntz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/13 16:31:08 by julmuntz #+# #+# */
/* Updated: 2022/05/30 15:09:50 by julmuntz ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
char chr;
char *str;
i = 0;
chr = (char)c;
str = (char *)s;
if (n == 0)
return (0);
while (i < n)
{
if (str[i] == chr)
return ((void *)str + i);
i++;
}
return (NULL);
}
/*
#include <stdio.h>
#include <string.h>
int main(void)
{
const char *str = "My name is Bond... James Bond";
const char chr = 'B';
char *ptr;
puts("\n- memchr");
ptr = memchr(str, chr, 007);
printf("Begins at first %c.\nThe output is: %s.\n", chr, ptr);
puts("\n- ft_memchr");
ptr = ft_memchr(str, chr, 007);
printf("Begins at first %c.\nThe output is: %s.\n", chr, ptr);
return 0;
}
*/