Compartilhar via


_strdup, _wcsdup (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Duplicate strings.

char *_strdup( const char *strSource );wchar_t *_wcsdup( const wchar_t *strSource);

Parameters

  • strSource
    Null-terminated source string.

Return Values

Both of these functions return a pointer to the storage location for the copied string or NULL if storage cannot be allocated.

Remarks

These functions are supported by all versions of the C run-time libraries.

The _strdup function calls malloc to allocate storage space for a copy of strSource and then copies strSource to the allocated space.

_wcsdup is a wide-character version of _strdup. The arguments and return value of _wcsdup are wide-character strings. These two functions behave identically otherwise.

The following table shows generic-text routine mappings for this function.

TCHAR.H Routine _UNICODE Defined
_tcsdup _wcsdup

For more information about TCHAR.H routines, see Generic Text Mappings.

Example

Description

The following example duplicates strings.

Code

#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

Requirements

OS Versions: Windows CE 2.0 and later.

Header: malloc.h, stdio.h, string.h.

Link Library: coredll.dll.

See Also

memset | strcat | strcmp | strncat | strncmp | strncpy

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.