ft_memcpy
Subject
MEMCPY(3) (simplified)
NAME
memcpy -- copy memory area
SYNOPSIS
void *memcpy(void *dst, const void *src, size_t n);
DESCRIPTION
The memcpy() function copies n bytes from memory area src to memory area dst. If dstt and src overlap, behavior is undefined. Applications in which dst and src might overlap should use memove(3) instead.
RETURN VALUES
The memcpy() function returns the original value of dst
Understandable explanation
The memcpy
function copies maximum n bytes from src
to dst
. The man talks about memory overlapping, I'll explain this with details on the memmove
function page.
As for memset
and bzero
we'll need some temporary pointers to manipulate our data.
This functions works like the strcpy
function, except that memcpy
accepts void *
as parameters, so we can give it any type of pointer we want to copy.
Hints
void *ft_memcpy(void *dst, const void *src, size_t n)
{
/* declare a temporary pointer for dst */
/* declare a temporary pointer for src */
/* if src and dst are NULL, return dst */
/* make dst tmp pointer equal to dst converted to unsigned char * */
/* make src tmp pointer equal to src converted to unsigned char * */
/* loop over the dst tmp pointer while we didn't reach n */
/* set the current byte of dst tmp pointer equal to current byte of src tmp pointer */
/* return dst */
}
Commented solution
Last updated
Was this helpful?