daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Jan 17th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. char *ft_strdup(const char *s1)
  2. {
  3.     char *s2;
  4.  
  5.     if ((s2 = ft_strnew(ft_strlen(s1))))
  6.         ft_strcpy(s2, (char *)s1);
  7.     return (s2);
  8. }
  9.  
  10.  
  11. //если не получится, то попробуй так
  12.  
  13. char        *ft_strdup(const char *s1)
  14. {
  15.     char    *s2;
  16.     int     count;
  17.     int     i;
  18.  
  19.     count = 0;
  20.     while (s1[count])
  21.         ++count;
  22.     if (!(s2 = (char*)malloc(sizeof(char) * (count + 1))))
  23.         return (NULL);
  24.     i = 0;
  25.     while (i < count)
  26.     {
  27.         s2[i] = s1[i];
  28.         ++i;
  29.     }
  30.     s2[count] = '\0';
  31.     return (s2);
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top