Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include "../includes/libft.h"
  5.  
  6. char *ft_strdup(const char *s1)
  7. {
  8.     char    *copy;
  9.     int     i;
  10.  
  11.     i = 0;
  12.     copy = NULL;
  13.     copy = (char *)malloc(sizeof(char) * ft_strlen(s1));
  14.     if (!(copy))
  15.     {
  16.         write(2, "Memory allocation error\n", 25);
  17.         return (NULL);
  18.     }
  19.     while (s1[i] != '\0')
  20.     {
  21.         copy[i] = s1[i];
  22.         i++;
  23.     }
  24.     copy[i] = '\0';
  25.     return (copy);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement