strdup

Creates a duplicate of a string

Local Servers:blocking
Remote Servers:N/A
Classification:Other
Service:String Manipulation

Syntax

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

Parameters

src
(IN) Points to the string to be copied.

Return Values

The strdup function returns the pointer to the new copy of the string if successful; otherwise, it returns NULL.

Remarks

The strdup function creates a duplicate of the string pointed to by src and returns a pointer to the new copy. The memory for the new string is obtained by using the malloc function and can be freed using the free function.

See Also

strcpy

Example

  #include <string.h>  
  #include <stdio.h>  
   
  main ()  
  {  
     char    *new;  
     new = strdup ("Make a copy");  
     printf (new);  
     free (new);  
  }