-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memchr.c
More file actions
38 lines (34 loc) · 1.3 KB
/
ft_memchr.c
File metadata and controls
38 lines (34 loc) · 1.3 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
35
36
37
38
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_memchr.c :+: :+: */
/* +:+ */
/* By: farodrig <farodrig@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/12/04 11:21:41 by farodrig #+# #+# */
/* Updated: 2020/12/12 18:48:05 by farodrig ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** Locates the first occurrence of c (converted to an unsigned char) in
** string s. Returns a pointer to the byte located, or NULL if no such byte
** exists within n bytes.
*/
void *ft_memchr(const void *str, int c, size_t len)
{
unsigned char *ptr;
size_t i;
ptr = (unsigned char*)str;
i = 0;
while (len)
{
if (ptr[i] == (unsigned char)c)
{
return (ptr + i);
}
i++;
len--;
}
return (0);
}