0

I was given this code to look at and find the problem of why its crashing or giving unexpected output. I can not seem to find it so a little hint or help would be great.

#include <string.h>
#include <stdio.h>

char* strdup(const char *s)
{
    size_t len = strlen(s);
    char d[len+1];
    return strncpy(d, s, len+1);
}

int main(int argc, char *argv[])
{
    int i;
    for(i = 1; i < argc; i++){
        puts(strdup(argv[i]));
    }

    return 0;
}

0 Answers0