-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memchr.c
More file actions
34 lines (30 loc) · 1.27 KB
/
ft_memchr.c
File metadata and controls
34 lines (30 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kmoutaou <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/07 13:18:34 by kmoutaou #+# #+# */
/* Updated: 2021/11/19 15:49:01 by kmoutaou ### ########.fr */
/* */
/* ************************************************************************** */
/*
ft_memchr is a re-coded memchr function from <string.h> that searches for
the first occurence of the character c in the first n bytes of the string
pointed to by str.
*/
#include "libft.h"
void *ft_memchr(const void *str, int c, size_t n)
{
unsigned char *str0;
str0 = (unsigned char *)str;
while ((int)n)
{
if (*str0 == (unsigned char)c)
return (str0);
str0++;
n--;
}
return (0);
}