0

In this case I'm trying to understand the difference between this wrong strdup and the good one.

char *wrong_strdup(char *str) {
    char *dest;

    dest = str;
    return (dest);
}
chqrlie
  • 131,814
  • 10
  • 121
  • 189
Myno
  • 158
  • 2
  • 13
  • 3
    All your function does is return its argument - i.e. it doesn't do anything. The real one does what it says it does. – Mat Jun 09 '20 at 16:03
  • 3
    Does this answer your question? https://stackoverflow.com/a/252802/4603670 – Barmak Shemirani Jun 09 '20 at 16:14
  • 2
    The real `strdup` is basically doing two things: allocates *new* memory for the duplicate and *copies* the string into this new memory. Your implementation does neither. – Eugene Sh. Jun 09 '20 at 16:22

0 Answers0