-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memccpy.c
33 lines (30 loc) · 1.23 KB
/
ft_memccpy.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: schetty <schetty@student.42kl.edu.my> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/06 22:06:27 by schetty #+# #+# */
/* Updated: 2021/11/10 02:37:15 by schetty ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memccpy(void *dest, const void *src, int c, size_t n)
{
size_t i;
unsigned char *ptr1;
unsigned char *ptr2;
unsigned char chr;
i = -1;
ptr1 = (unsigned char *)dest;
ptr2 = (unsigned char *)src;
chr = (unsigned char)c;
while (++i < n)
{
ptr1[i] = ptr2[i];
if (ptr2[i] == chr)
return (ptr1 + i + 1);
}
return (NULL);
}