Definition | #include <string.h> size_t strxfrm(char *s1, const char *s2, size_t n);
A comparison of two strings transformed with |
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 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 |