create a duplicate of a string
#include <string.h> char *strdup( const char *src ); char *_strdup( const char *src ); char __far *_fstrdup( const char __far *src );
The strdup() and _fstrdup() functions create a duplicate of the string pointed to by src, and returns a pointer to the new copy. For strdup(), the memory for the new string is obtained by using the malloc() function, and can be freed using the free() function. For _fstrdup(), the memory for the new string is obtained by using the _fmalloc() function, and can be freed using the _ffree() function.
The _strdup() function is identical to strdup(). Use _strdup() for ANSI naming conventions.
The _fstrdup() function is a data-model-independent form of the strdup() function that accepts far pointer arguments. It is most useful in mixed memory model applications.
the pointer to the new copy of the string if successful, otherwise NULL
free(), malloc(), strcpy(), strncpy()
#include <stdio.h> #include <string.h> void main() { char *dup; dup = strdup( "Make a copy" ); printf( "%s\n", dup ); }
WATCOM
_strdup() conforms to ANSI naming conventions.