-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memccpy.c
executable file
·35 lines (32 loc) · 1.31 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
34
35
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cyildiri <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/09/25 21:21:36 by cyildiri #+# #+# */
/* Updated: 2016/09/26 14:27:37 by cyildiri ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
size_t index;
unsigned char *src_ptr;
unsigned char *dst_ptr;
index = 0;
src_ptr = (unsigned char *)src;
dst_ptr = (unsigned char *)dst;
while (index < n)
{
dst_ptr[index] = src_ptr[index];
if (dst_ptr[index] == (unsigned char)c)
return (&dst_ptr[index + 1]);
index++;
}
if (index == n)
return (NULL);
else
return (&dst_ptr[index]);
}