daily pastebin goal
72%
SHARE
TWEET

Untitled

a guest Jan 17th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <unistd.h>
  3. #include <string.h>
  4.  
  5. char *ft_strdup(char *src)
  6. {
  7. int i;
  8. int len;
  9. char *str;
  10.  
  11. len = 0;
  12. while (src[len])
  13. len++;
  14. str = (char *)malloc(sizeof(*str) * (len + 1));
  15. i = 0;
  16. while (i < len)
  17. {
  18. str[i] = src[i];
  19. i++;
  20. }
  21. return (str);
  22. }
  23.  
  24. void ft_print_result(char const *s)
  25. {
  26. int len;
  27.  
  28. len = 0;
  29. while (s[len])
  30. len++;
  31. write(1, s, len);
  32. }
  33.  
  34. int main(int argc, const char *argv[])
  35. {
  36. char str[] = "lorem ipsum dolor sit amet";
  37. char *str_dup;
  38.  
  39. alarm(5);
  40. if (argc == 1)
  41. return (0);
  42. if (atoi(argv[1]) == 1)
  43. {
  44. if (!(str_dup = ft_strdup(str)))
  45. ft_print_result("NULL");
  46. else
  47. ft_print_result(str_dup);
  48. if (str_dup == str)
  49. ft_print_result("\nstr_dup's adress == str's adress");
  50. }
  51. return (0);
  52. }
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