-
Notifications
You must be signed in to change notification settings - Fork 2
/
ft_memchr.c
37 lines (33 loc) · 1.32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adiaz-lo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/21 13:21:00 by adiaz-lo #+# #+# */
/* Updated: 2020/01/13 09:33:19 by adiaz-lo ### ########.fr */
/* */
/* ************************************************************************** */
/*
** This function scans the first 'n' bytes of 's' for the first occurrence of
** 'c'.
** For further information, please check the Standard C Library function
** 'memchr(const void *s, int c, size_t n)'
*/
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *str;
size_t i;
str = (unsigned char *)s;
c = (unsigned char)c;
i = 0;
while (i < n)
{
if (str[i] == c)
return ((void *)str + i);
i++;
}
return (0);
}