Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include "../includes/libft.h"
- char *ft_strdup(const char *s1)
- {
- char *copy;
- int i;
- i = 0;
- copy = NULL;
- copy = (char *)malloc(sizeof(char) * ft_strlen(s1));
- if (!(copy))
- {
- write(2, "Memory allocation error\n", 25);
- return (NULL);
- }
- while (s1[i] != '\0')
- {
- copy[i] = s1[i];
- i++;
- }
- copy[i] = '\0';
- return (copy);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement