Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

strxfrm - Transform a string

&pagelevel(4)&pagelevel

Definition   

#include <string.h>

size_t strxfrm(char *s1, const char *s2, size_t n);

strxfrm transforms the characters in string s2 so that the lexical sequence of each character is interpreted according to the LC_COLLATE category of the current locale.
A maximum of n transformed characters (including the terminating null byte) are then copied to string s1.
If n has the value 0 then result string s1 can be a NULL pointer.

A comparison of two strings transformed with strxfrm using the strcmp function will then return the same result as a comparison with the strcoll function applied to the same original strings.

Return val.

Length of the transformed string (excluding the terminating null byte).

Notes

A string terminated with the null byte (\0) is expected as argument s2.

String s2 is not modified by strxfrm. The transformation is performed in a work area.

If the return value is greater than or equal to n, the contents of string s1 are indeterminate because no null byte was written.

If the hexadecimal value 0 has been assigned to one of the characters in string s2 in the current locale, then this character terminates the transformed string as the null byte (see also section “User-specific locales”).

The behavior is undefined if memory areas overlap.

The locale concept is described in detail in chapter “Locale”.

Example

#include <stdio.h>
#include <string.h>
#include <locale.h>
int main(void)
{
  char alpha2[11];
  char num2[11];
  int comp1;
  int comp2;
  int comp3;
  size_t i = 11;
  char *alpha1 = "ABCDEFGHIJ";
  char *num1 = "0123456789";
  setlocale(LC_COLLATE, "ANNE");       /* Activate the user-specific
                                          locale, in which digits have
                                          a lower sorting value than
                                          letters */
  comp1 = strcoll(alpha1, num1);       /* Compare the original strings */
  if(comp1 > 0)                        /* using strcoll */
     printf ("alpha1 greater than num1\n");
  else printf("Fehler\n");
  comp2 = strcmp(alpha1, num1);        /* Compare the original strings */
  if(comp2 < 0)                        /* using strcmp */
     printf ("alpha1 less than num1\n");
  else printf("Error\n");
  strxfrm(num2, num1, i);              /* Transform with strxfrm */
  strxfrm(alpha2, alpha1, i);
  comp3 = strcmp(alpha2, num2);        /* Compare the transformed */
  if(comp3 > 0)                        /* result strings using strcmp */
     printf ("alpha2 greater than num2\n");
  else printf("Error\n");
  return 0;
  }

See also

setlocale, strcoll, strcmp