Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo 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);
 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.  No overflow checking is done when strings
                    are copied or appended.

   -------------------------------- Example ---------------------------------

    The following statements make a copy of 'jelly beans' and print 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()

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