Monday, July 23, 2012

Write your own C program to implement "strdup()" function.





char *mystrdup(char *s)
{
char *result = (char*)malloc(strlen(s)*sizeof(char) + 1);
if (result == NULL)
{
    return NULL;
}
strcpy(result, s);
return result;
}

No comments:

Post a Comment