eg0rmaffin

strdup

Sep 4th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int ft_strlen(char *str)
  5. {
  6.     int c;
  7.  
  8.     c = 0;
  9.     while (str[c] != 0)
  10.     {
  11.         c++;
  12.     }
  13.     return (c);
  14. }
  15.  
  16. char    *ft_strdup(char *src)
  17. {
  18.     char *dst;
  19.     int a;
  20.     int run;
  21.    
  22.     run = 0;
  23.     a = ft_strlen(src);
  24.     dst = (char*)malloc(sizeof(char) * a);
  25.     while (run != a)
  26.     {
  27.         dst[run] = src[run];
  28.         run++;
  29.     }
  30.     dst[run] = '\0';
  31.     return (dst);
  32. }
  33.  
  34.  
  35. int main()
  36. {
  37.     char *hui;
  38.     hui = "sosipidaraz";
  39.     printf("%s", ft_strdup(hui));
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment