wcsncat() — Concatenate Wide-Character Strings

Format

#include <wchar.h>
wchar_t *wcsncat(wchar_t *string1, const wchar_t *string2, size_t count);

Language Level: XPG4

Threadsafe: Yes.

Wide Character Function: See Wide Characters for more information.

Description

The wcsncat() function appends up to count wide characters from string2 to the end of string1, and appends a wchar_t null character to the result.

The wcsncat() function operates on null-ending wide-character strings; string arguments to this function should contain a wchar_t null character marking the end of the string.

Return Value

The wcsncat() function returns string1.

Example that uses wcsncat()

This example demonstrates the difference between the wcscat() and wcsncat()functions. The wcscat() function appends the entire second string to the first; the wcsncat()function appends only the specified number of characters in the second string to the first.

#include <stdio.h>
#include <wchar.h>
#include <string.h>
 
#define SIZE 40
 
int main(void)
{
  wchar_t buffer1[SIZE] = L"computer";
  wchar_t * ptr;
 
  /* Call wcscat with buffer1 and " program" */
 
  ptr = wcscat( buffer1, L" program" );
  printf( "wcscat : buffer1 = \"%ls\"\n", buffer1 );
 
  /* Reset buffer1 to contain just the string "computer" again */
 
  memset( buffer1, L'\0', sizeof( buffer1 ));
  ptr = wcscpy( buffer1, L"computer" );
 
  /* Call wcsncat with buffer1 and " program" */
  ptr = wcsncat( buffer1, L" program", 3 );
  printf( "wcsncat: buffer1 = \"%ls\"\n", buffer1 );
}
/****************  Output should be similar to: ******************
 
wcscat : buffer1 = "computer program"
wcsncat: buffer1 = "computer pr"
*/

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]