-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_memccpy.c
35 lines (32 loc) · 1.3 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: ksmorozo <ksmorozo@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/10/31 19:27:11 by ksmorozo #+# #+# */
/* Updated: 2021/07/07 12:17:08 by ksmorozo ######## odam.nl */
/* */
/* ************************************************************************** */
#include <stddef.h>
void *ft_memccpy(void *dest, const void *src, int c, size_t n)
{
unsigned char *buffer1;
unsigned char *buffer2;
size_t count;
buffer1 = (unsigned char *)src;
buffer2 = (unsigned char *)dest;
count = 0;
while (count < n)
{
if (buffer1[count] == (unsigned char)c)
{
buffer2[count] = buffer1[count];
return (buffer2 + count + 1);
}
buffer2[count] = buffer1[count];
count++;
}
return (NULL);
}