strdup()                 Duplicate String
 
 #include   <string.h>
 
 char       *strdup(string);
 char       *string;                     Source string
 
    strdup() makes a copy of 'string'.  It allocates space for the string
    with a call to malloc().
 
    Returns:    A pointer to the storage location containing the
                duplicate string. NULL is returned if space could not be
                allocated.
 
      Notes:    strdup() expects to operate on null-terminated strings.
                No overflow checking is done when strings are copied or
                appended.
 
  -------------------------------- Example ---------------------------------
 
    This example makes a copy of 'jelly beans' and prints it out.
 
         #include <string.h>
         #include <stdio.h>      /* for printf */
 
         char string[20] = "jelly beans";
         char *rslt;
 
         main()
         {
                if ((rslt = strdup(string)) == NULL)
                   printf("memory could not be allocated");
                else
                    printf("%s",rslt);
          }

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster