Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C - <b>strdup() duplicate string</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
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);
          }

See Also:

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson