C Standard Library

C <wchar.h> - wcsxfrm() Function



The C <wchar.h> wcsxfrm() function transforms a null-terminated wide string pointed to by src according to the current locale and copies the first num wide characters of the transformed string to dest, including the terminating null wide character, and the length of the full transformed string is returned, excluding the terminating null wide character.

If num is 0, then dest will be a null pointer. The behavior is undefined if dest and src overlap.

The behavior of the function depends on the LC_COLLATE category of the selected C locale.

Syntax

size_t wcsxfrm ( wchar_t* dest, const wchar_t* src, size_t num );       

Parameters

dest Specify pointer to the first element of the array where the transformed string to be copied.
src Specify pointer to the first character of a null-terminated wide string to transform.
num Specify maximum number of wide characters to copy.
size_t is an unsigned integer type.

Return Value

Returns the length of the full transformed wide string, excluding the terminating null wide character.

Example:

The example below shows the usage of wcsxfrm() function.

#include <stdio.h>
#include <locale.h>
#include <wchar.h>
 
int main (){
  wchar_t dest[20];
  wchar_t src[20] = L"Hello World";
  
  //using LC_COLLATE of Minimal C locale
  setlocale(LC_COLLATE,"C");

  //transforming src into dest 
  int retval = wcsxfrm(dest, src, 20);

  //displaying the result
  printf("dest contains: %ls\n", dest);
  printf("length of full transformed wide string: %d\n",
          retval);

  return 0;
}

The output of the above code will be:

dest contains: Hello World
length of full transformed wide string: 11

❮ C <wchar.h> Library