StrDupStrDup*
*



Contents  *



Index  *Topic Contents
*Previous Topic: StrCSpnI
*Next Topic: StrFormatByteSize

StrDup


LPTSTR StrDup( 
    LPCTSTR lpsz 
    );

Duplicates a string.

lpsz
Address of a constant null-terminated character string.

StrDup will allocate storage the size of the original string. If storage allocation is successful, the original string is copied to the duplicate string.

Example:

#include <windows.h>
#include <string.h>
#include <stdio.h>

void main( void )
{
   char buffer[] = "This is the buffer text";
   char *newstring;
   printf( "Original: %s\n", buffer );
   newstring = StrDup( buffer );
   printf( "Copy:     %s\n", newstring );
   free( newstring );
}

   OUTPUT:
   - - - - - - 
   Original: This is the buffer text
   Copy:     This is the buffer text

Note This function uses LocalAlloc to allocate storage space for the copy of the string. The calling application must free this memory by calling the LocalFree function on the pointer returned by the call to StrDup.


Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.