-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memchr.c
More file actions
32 lines (29 loc) · 1.19 KB
/
ft_memchr.c
File metadata and controls
32 lines (29 loc) · 1.19 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_memchr.c :+: :+: */
/* +:+ */
/* By: nsterk <nsterk@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/10/26 14:05:46 by nsterk #+# #+# */
/* Updated: 2020/11/14 23:01:52 by nsterk ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *sptr;
unsigned char uc;
sptr = (unsigned char *)s;
uc = (unsigned char)c;
if (!n || (uc == '\0' && (n < (size_t)ft_strlen(s))))
return (NULL);
while (n)
{
if (*sptr == uc)
return (sptr);
sptr++;
n--;
}
return (NULL);
}