-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memchr.c
More file actions
33 lines (29 loc) · 1.26 KB
/
ft_memchr.c
File metadata and controls
33 lines (29 loc) · 1.26 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fsanz-ex <fsanz-ex@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/02 15:54:51 by fsanz-ex #+# #+# */
/* Updated: 2023/02/09 19:58:35 by fsanz-ex ### ########.fr */
/* */
/* ************************************************************************** */
#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 *s, int c, size_t n)
{
unsigned char *str;
size_t i;
i = 0;
str = (void *) s;
while (i < n)
{
if (str[i] == (unsigned char) c)
return (&str[i]);
i++;
}
return (NULL);
}