Name

wcscat

Synopsis

Appends one wide string to another

#include <wchar.h>
wchar_t *wcscat( wchar_t * restrict s1, const wchar_t * restrict s2 );

The wcscat() function copies the wide character string addressed by the second pointer argument, s2, to the location following the string addressed by the first pointer, s1. The first wide character of s2 is copied over the terminating null wide character of the string addressed by s1. The function returns the value of its first argument, which points to the concatenated string.

There is no limit to the number of characters wcscat() may write before it encounters a null wide character in the source string. It is up to you the programmer to make sure that there is enough storage available at the destination to accommodate the result. You should consider using wcsncat() instead to reduce the risk of buffer overflows. You must also make sure that the locations that wcscat() reads from and writes to do not overlap.

Example

typedef struct {
  wchar_t  lastname[32];
  wchar_t  firstname[32];
  _Bool ismale;
} Name;

  wchar_t displayname[80];
  Name *newName = calloc( 1, sizeof(Name) );

/* ... check for calloc failure; read in the name parts ... */

if ( newName != NULL )
{

  fputws( L"Enter <last name>, <first name>:", stdout );
  wscanf( L"%32l[^,]%*[,] %32ls", newName->lastname, newName->firstname );

  wcscpy( displayname, ( newName->ismale ? L"Mr. " : L"Ms. " ) );wcscat( displayname, newName->firstname );
  wcscat( displayname, L" " );
  wcscat( displayname, newName->lastname ...

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.