correction memcpy pour le cas ou dst et src sont nuls
This commit is contained in:
BIN
srcs/.DS_Store
vendored
BIN
srcs/.DS_Store
vendored
Binary file not shown.
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:16 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:56:17 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/11/28 13:45:23 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -14,18 +14,37 @@
|
||||
** copy n characters from src to dst and return dst
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** void *ft_memcpy(void *dst, const void *src, size_t n);
|
||||
**
|
||||
** int main(int ac, char **av)
|
||||
** {
|
||||
** if (ac == 4)
|
||||
** {
|
||||
** printf("%s\n", ft_memcpy(av[1], av[2], atoi(av[3])));
|
||||
** }
|
||||
** else
|
||||
** {
|
||||
** printf("%s\n", ft_memcpy("troubadour", "bravo", 4));
|
||||
** }
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
char *ptr;
|
||||
char *ptr2;
|
||||
|
||||
ptr = (char *)dst;
|
||||
ptr2 = (char *)src;
|
||||
i = -1;
|
||||
while (++i < n)
|
||||
ptr[i] = ptr2[i];
|
||||
if (dst == src)
|
||||
return (dst);
|
||||
while (n--)
|
||||
ptr[n] = ptr2[n];
|
||||
return (dst);
|
||||
}
|
||||
BIN
srcs/part2/a.out
BIN
srcs/part2/a.out
Binary file not shown.
Reference in New Issue
Block a user