-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memchr.c
executable file
·35 lines (31 loc) · 1.23 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mwilliam <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/11 18:47:43 by mwilliam #+# #+# */
/* Updated: 2016/12/02 10:24:31 by mwilliam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** Locates the first occurence of c in the string s
*/
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned const char *str;
unsigned char d;
size_t index;
str = (unsigned const char *)s;
d = c + '\0';
index = 0;
while (index < n)
{
if (str[index] == d)
return ((void *)s + index);
index++;
}
return (NULL);
}