-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memcpy.c
45 lines (40 loc) · 1.61 KB
/
ft_memcpy.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
36
37
38
39
40
41
42
43
44
45
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dolvin17 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/21 17:51:11 by ghuertas #+# #+# */
/* Updated: 2022/04/25 11:01:35 by dolvin17 ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* copia un área de memoria apuntada por *src
al área de memoria apuntada por *dest*/
void *ft_memcpy(void *dest, const void *src, size_t n)
{
unsigned char *dp;
const unsigned char *sp;
if (!dest && !src) // si origen o destino son nulos
return (0);//retorno null.
dp = dest;
sp = src;
while (n--)//el tamaño de mi buffer sea distinto de cero.
{
*dp++ = *sp++; //igualo y aumento mi puntero de destino al de la fuente.
}
return (dest);//retorno dest modificado.
}
/*
#include <stdio.h>
#include <string.h>
int main(void)
{
char dest[] = "marvin5";
char src[] = "abcdcd";
unsigned n = 5;
printf("mine: %p\n", ft_memcpy(&dest, &src, n));
printf("original: %p\n", memcpy(&dest, &src, n));
return (0);
}*/