PS-Trainer C - Entwicklung
Bibliotheks-Funktionen: 2 Strings RW
Homepage von PS-Trainer - C-Entwicklung - Strings - an PS-Trainer
PS-Trainer PS-Trainer

Strings & characters Overview
strncpy, wcsncpy, _mbsncpy Copy characters of one string to another.
strcpy, wcscpy, _mbscpy Copy a string.
_strdup, _wcsdup, _mbsdup Duplicate strings.
strncat, wcsncat, _mbsncat
Append characters of a string.
strcat, wcscat, _mbscat
Append a string.


strncat, wcsncat, _mbsncat
Append characters of a string.
char *strncat( char *strDest, const char *strSource, size_t count );
wchar_t *wcsncat( wchar_t *strDest, const wchar_t *strSource, size_t count );
unsigned char *_mbsncat( unsigned char *strDest, const unsigned char *strSource, size_t count);


Routine Required Header Compatibility
strncat <string.h> ANSI, Win 95, Win NT
wcsncat <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbsncat <mbstring.h> Win 95, Win NT

Remarks
The strncat function appends, at most, the first count characters of strSource to strDest. The initial character of strSource overwrites the terminating null character of strDest. If a null character appears in strSource before count characters are appended, strncat appends all characters from strSource, up to the null character. If count is greater than the length of strSource, the length of strSource is used in place of count. The resulting string is terminated with a null character. If copying takes place between strings that overlap, the behavior is undefined.
wcsncat and _mbsncat are wide-character and multibyte-character versions of strncat. The string arguments and return value of wcsncat are wide-character strings; those of _mbsncat are multibyte-character strings. These three functions behave identically otherwise.

Generic-Text Routine Mappings
TCHAR.H _UNICODE & _MBCS _MBCS _UNICODE
Routine Not Defined Defined Defined
_tcsncat strncat _mbsncat wcsncat

Subject: String Manipulation Routines
Keywords: See Also _mbsnbcat, strcat, strcmp, strcpy, strncmp, strncpy, _strnicmp, strrchr, _strset, strspn
Return Value
Each of these functions returns a pointer to the destination string. No return value is reserved to indicate an error.

Parameters
strDest Null-terminated destination string
strSource Null-terminated source string
count Number of characters to append

Example
/* STRNCAT.C */

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

void main( void )
{
char string[80] = "This is the initial string!";
char suffix[] = " extra text to add to the string...";
/* Combine strings with no more than 19 characters of suffix: */
printf( "Before: %s\n", string );
strncat( string, suffix, 19 );
printf( "After: %s\n", string );
}


Output
Before: This is the initial string!
After: This is the initial string! extra text to add


strcat, wcscat, _mbscat
Append a string.
char *strcat( char *strDestination, const char *strSource );
wchar_t *wcscat( wchar_t *strDestination, const wchar_t *strSource );
unsigned char *_mbscat( unsigned char *strDestination, const unsigned char *strSource );


Routine Required Header Compatibility
 strcat <string.h> ANSI, Win 95, Win NT
 wcscat <string.h> or <wchar.h> ANSI, Win 95, Win NT
 _mbscat <mbstring.h> Win 95, Win NT

Remarks
The strcat function appends strSource to strDestination and terminates the resulting string with a null character. The initial character of strSource overwrites the terminating null character of strDestination. No overflow checking is performed when strings are copied or appended. The behavior of strcat is undefined if the source and destination strings overlap.
wcscat and _mbscat are wide-character and multibyte-character versions of strcat. The arguments and return value of wcscat are wide-character strings; those of _mbscat are multibyte-character strings. These three functions behave identically otherwise.

Generic-Text Routine Mappings
TCHAR.H _UNICODE & _MBCS _MBCS _UNICODE
Routine Not Defined Defined Defined
_tcscat strcat _mbscat wcscat

Subject: String Manipulation Routines
Keywords: See Also strncat, strncmp, strncpy, _strnicmp, strrchr, strspn
Return Value
Each of these functions returns the destination string (strDestination). No return value is reserved to indicate an error.

Parameters
strDestination Null-terminated destination string
strSource Null-terminated source string

Example
/* STRCPY.C: This program uses strcpy
* and strcat to build a phrase.
*/

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

void main( void )
{
char string[80];
strcpy( string, "Hello world from " );
strcat( string, "strcpy " );
strcat( string, "and " );
strcat( string, "strcat!" );
printf( "String = %s\n", string );
}


Output
String = Hello world from strcpy and strcat!


strncpy, wcsncpy, _mbsncpy
Copy characters of one string to another.
char *strncpy( char *strDest, const char *strSource, size_t count );
wchar_t *wcsncpy( wchar_t *strDest, const wchar_t *strSource, size_t count );
unsigned char *_mbsncpy( unsigned char *strDest, const unsigned char *strSource, size_t count );


Routine Required Header Compatibility
 strncpy <string.h> ANSI, Win 95, Win NT
 wcsncpy <string.h> or <wchar.h> ANSI, Win 95, Win NT
 _mbsncpy <mbstring.h> Win 95, Win NT

Remarks
The strncpy function copies the initial count characters of strSource to strDest and returns strDest. If count is less than or equal to the length of strSource, a null character is not appended automatically to the copied string. If count is greater than the length of strSource, the destination string is padded with null characters up to length count. The behavior of strncpy is undefined if the source and destination strings overlap.
wcsncpy and _mbsncpy are wide-character and multibyte-character versions of strncpy. The arguments and return value of wcsncpy and _mbsncpy vary accordingly. These three functions behave identically otherwise.

Generic-Text Routine Mappings
TCHAR.H _UNICODE & _MBCS _MBCS _UNICODE
Routine Not Defined Defined Defined
_tcsncpy strncpy _mbsncpy wcsncpy

Subject: String Manipulation Routines
Keywords: See Also _mbsnbcpy, strcat, strcmp, strcpy, strncat, strncmp, _strnicmp, strrchr, _strset, strspn
Return Value
Each of these functions returns the string strDest. No return value is reserved to indicate an error.

Parameters
strDest Destination string
strSource Source string
count Number of characters to be copied

Example
/* STRNCPY.C */

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

void main( void )
{
char string[100] = "Cats are nice usually";
printf ( "Before: %s\n", string );
strncpy( string, "Dogs", 4 );
strncpy( string + 9, "mean", 4 );
printf ( "After: %s\n", string );
}


Output
Before: Cats are nice usually
After: Dogs are mean usually


strcpy, wcscpy, _mbscpy
Copy a string.
char *strcpy( char *strDestination, const char *strSource );
wchar_t *wcscpy( wchar_t *strDestination, const wchar_t *strSource );
unsigned char *_mbscpy( unsigned char *strDestination, const unsigned char *strSource );


Routine Required Header Compatibility
 strcpy <string.h> ANSI, Win 95, Win NT
 wcscpy <string.h> or <wchar.h> ANSI, Win 95, Win NT
 _mbscpy <mbstring.h> Win 95, Win NT

Remarks
The strcpy function copies strSource, including the terminating null character, to the location specified by strDestination. No overflow checking is performed when strings are copied or appended. The behavior of strcpy is undefined if the source and destination strings overlap.
wcscpy and _mbscpy are wide-character and multibyte-character versions of strcpy. The arguments and return value of wcscpy are wide-character strings; those of _mbscpy are multibyte-character strings. These three functions behave identically otherwise.

Generic-Text Routine Mappings
TCHAR.H _UNICODE & _MBCS _MBCS _UNICODE
Routine Not Defined Defined Defined
_tcscpy strcpy _mbscpy wcscpy

Subject: String Manipulation Routines
Keywords: See Also strcat, strcmp, strncat, strncmp, strncpy, _strnicmp, strrchr, strspn
Return Value
Each of these functions returns the destination string. No return value is reserved to indicate an error.

Parameters
strDestination Destination string
strSource Null-terminated source string

Example
/* STRCPY.C: This program uses strcpy
* and strcat to build a phrase.
*/

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

void main( void )
{
char string[80];
strcpy( string, "Hello world from " );
strcat( string, "strcpy " );
strcat( string, "and " );
strcat( string, "strcat!" );
printf( "String = %s\n", string );
}


Output
String = Hello world from strcpy and strcat!


_strdup, _wcsdup, _mbsdup
Duplicate strings.
char *_strdup( const char *strSource );
wchar_t *_wcsdup( const wchar_t *strSource );
unsigned char *_mbsdup( const unsigned char *strSource );


Routine Required Header Compatibility
 _strdup <string.h> Win 95, Win NT
 _wcsdup <string.h> or <wchar.h> Win 95, Win NT
 _mbsdup <mbstring.h> Win 95, Win NT

Remarks
The _strdup function calls malloc to allocate storage space for a copy of strSource and then copies strSource to the allocated space.
_wcsdup and _mbsdup are wide-character and multibyte-character versions of _strdup. The arguments and return value of _wcsdup are wide-character strings; those of _mbsdup are multibyte-character strings. These three functions behave identically otherwise.

Generic-Text Routine Mappings
TCHAR.H _UNICODE & _MBCS _MBCS _UNICODE
Routine Not Defined Defined Defined
_tcsdup _strdup _mbsdup _wcsdup

Because _strdup calls malloc to allocate storage space for the copy of strSource, it is good practice always to release this memory by calling the free routine on the pointer returned by the call to _strdup.

Subject: String Manipulation Routines
Keywords: See Also memset, strcat, strcmp, strncat, strncmp, strncpy, _strnicmp, strrchr, strspn

Return Value
Each of these functions returns a pointer to the storage location for the copied string or NULL if storage cannot be allocated.

Parameter
strSource Null-terminated source string

Example
/* STRDUP.C */

#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


Homepage von PS-Trainer - C-Entwicklung - Strings - an PS-Trainer

Aktuelle Daten dieser Seite Letzte Änderung:
  Geocities

 

 

 

Hosted by www.Geocities.ws

1