C Standard Library

C <string.h> - strxfrm() Function



The C <string.h> strxfrm() function transforms a null-terminated byte string pointed to by src according to the current locale and copies the first num characters of the transformed string to dest, including the terminating null character, and the length of the full transformed string is returned, excluding the terminating null 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 strxfrm ( char * dest, const char * 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 byte string to transform.
num Specify maximum number of characters to copy.
size_t is an unsigned integer type.

Return Value

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

Example:

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

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

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

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

  return 0;
}

The output of the above code will be:

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

❮ C <string.h> Library