ft_memcpy()

This commit is contained in:
Leonardo Algarra 2025-10-04 19:08:56 +02:00
parent 78e40cde0d
commit d0f019dbc0
3 changed files with 46 additions and 2 deletions

View file

@ -6,7 +6,7 @@
# By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ # # By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2025/10/03 18:03:12 by lalgarra #+# #+# # # Created: 2025/10/03 18:03:12 by lalgarra #+# #+# #
# Updated: 2025/10/04 16:35:10 by lalgarra ### ########.fr # # Updated: 2025/10/04 16:57:22 by lalgarra ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -18,7 +18,7 @@ CFLAGS += -Wall -Wextra -Werror -g3 -iquote $(LIBDIR)
TESTS := ft_isalpha_test ft_isdigit_test ft_isalnum_test ft_isascii_test \ TESTS := ft_isalpha_test ft_isdigit_test ft_isalnum_test ft_isascii_test \
ft_isprint_test ft_toupper_test ft_tolower_test ft_strlen_test \ ft_isprint_test ft_toupper_test ft_tolower_test ft_strlen_test \
ft_memset_test ft_bzero_test ft_memset_test ft_bzero_test ft_memcpy_test
%_test : %_test.c %_test : %_test.c
$(CC) $(CFLAGS) $*_test.c -L$(LIBDIR) -lft -o $*_test $(CC) $(CFLAGS) $*_test.c -L$(LIBDIR) -lft -o $*_test

View file

@ -0,0 +1,3 @@
src: "Iorem ipsum dolor", n=0, dest: "_________________"; after call, dest: "_________________"; (res == dest): 1
src: "Iorem ipsum dolor", n=3, dest: "_________________"; after call, dest: "Ior______________"; (res == dest): 1
src: "Iorem ipsum dolor", n=17, dest: "_________________"; after call, dest: "Iorem ipsum dolor"; (res == dest): 1

41
ft_memcpy_test.c Normal file
View file

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/03 18:27:44 by lalgarra #+# #+# */
/* Updated: 2025/10/04 19:06:34 by lalgarra ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdio.h>
#include <string.h>
void do_test1(char *dest, char *src, size_t n)
{
void *res;
printf("src: \"%s\", n=%lu, dest: \"%s\";", src, n, dest);
res = memcpy(dest, src, n);
printf(" after call, dest: \"%s\";", dest);
printf(" (res == dest): %i\n", res == (void *)dest);
}
int main(void)
{
char src[18];
char dest[18];
strcpy(src, "Iorem ipsum dolor\0");
ft_memset(dest, '_', 17);
dest[17] = '\0';
do_test1(dest, src, 0);
ft_memset(dest, '_', 17);
do_test1(dest, src, 3);
ft_memset(dest, '_', 17);
do_test1(dest, src, 17);
return (0);
}