answersLogoWhite

0

char *strdup (const char *s)

{

size_t len;

char *p;

if ( !s )

return NULL;

len = strlen (s);

p = malloc (len+1);

if (p && len)

{

memcpy (p, s, len);

p[len] = '\0';

}

return p;

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Write a program of binary heap in c or c language?

to implement operations on binary heap in c


Write a program in c language to implement framing methods like character stuffing?

A program in c language to implement framing methods like character stuffing can be grave sizeCRC-32 and the variable c50.


How do you run graphics program in C?

pro c language to implement linear search using pointers


C program to implement arithmetic assignment operator?

y=2x2+3x+1


How can use Strdup function in c language?

char* duplicated strdup("Hello World"); duplicated will now contain the address to dynamically allocated memory of a C-style string that contains "Hello World" and a null at the end. Be sure to free duplicated when you're done with it or you'll have a memory leak.


How do you implement a program to display the Indian flag with colors using c graphics?

ANSI/ISO C does not and never has done graphics.


Write a program in C language to implement the apriori algorithm?

JavaScript is one program that has been written in C to implement the Apriori algorithm. There are also several other known programs available on the Internet that implement it as well.


Write a program in c plus plus to implement macro processor?

Don't write, it is already written, google for 'cpp'.


C program to implement tower of hanoi using array implementation of stack abstract datatype?

stack abstract datatype


How do you allocate memory dynamically for a string of unknown size in c?

With function strdup (here is an implementation, if you don't have one already)char *strdup (const char *f){size_t len;char *to;len= strlen (f);to = malloc (len+1);if (to) memcpy (to, f, len+1);return to;}


Why c is top down approach?

It doesn't. Programmers might use any approach they like.


What is the name of Russian leader who followed Peter the Great and continued to implement his program?

Catherine followed Peter the Great and continued to implement his program.