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 6.0 - <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);
 const 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.
                There is no overflow checking when strings are copied or
                appended.

 Portability:   strdup() is a Microsoft extension to the ANSI standard;
                it should not ber used when ANSI compatibility is
                required.

   -------------------------------- 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: strcpy() strncpy()

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