Name

strdup - duplicate a string

Library

libc.lib

Synopsis

  #include <string.h>
  char * strdup (const char *str);

Detailed description

The strdup function allocates sufficient memory for a copy of the string str, does the copy, and returns a pointer to it. The pointer may subsequently be used as an argument to the function free (see malloc.

If insufficient memory is available, NULL is returned and errno is set to ENOMEM.


Examples

#include <string.h>
#include <stdio.h>
int main()
{
    char* ptr;
    ptr = (char *)strdup("abcde");
    printf("Duplicated string %s\n",ptr);
    ptr = (char *)strdup("Hello Hi");
    printf("Duplicated string %s\n",ptr);
    return 0;   
}


Output

Duplicated string abcde
Duplicated string Hello Hi


Return value

The strdup() function returns a pointer to the duplicated string, or NULL if insufficient memory was available.

See also

malloc

Feedback

For additional information or queries on this page send feedback

© 2008 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user.

Top