feat: add ft_memcpy function

This commit is contained in:
2025-09-30 19:48:32 +02:00
parent 63d4127817
commit bfbee5b3a9
2 changed files with 28 additions and 0 deletions

18
ft_memcpy.c Normal file
View File

@@ -0,0 +1,18 @@
#include "libft.h"
void *ft_memcpy(void *dst, const void *src, size_t n)
{
size_t i;
char *srctmp;
char *dsttmp;
i = 0;
srctmp = (char *)src;
dsttmp = (char *)dst;
while (i < n)
{
dsttmp[i] = srctmp[i];
i++;
}
return (dst);
}

10
libft.h
View File

@@ -61,4 +61,14 @@ void *ft_memset(void *b, int c, size_t len);
*/ */
void ft_bzero(void *s, size_t n); void ft_bzero(void *s, size_t n);
/*
The memcpy() function copies n bytes
from memory area src to memory area dst.
If dst and src overlap, behavior is
undefined. Applications in which dst and
src might overlap should use memmove(3)
instead.
*/
void *ft_memcpy(void *dst, const void *src, size_t n);
#endif #endif