Format
#include <wctype.h> wctrans_t wctrans(const char *property);
Language Level: ANSI
Threadsafe: Yes.
Description
The wctrans() function constructs a value with type wctrans_t. This value describes a mapping between wide characters identified by the string argument property. The two strings listed under the towctrans() function description shall be valid in all locales as property arguments to the wctrans() function.
Return Value
If property identifies a valid mapping of wide characters according to the LC_CTYPE category of the current locale, the wctrans() function returns a nonzero value that is valid as the second argument to the towctrans() function. Otherwise, it returns 0.
Example that uses wctrans()
This example translates the lowercase alphabet to uppercase, and back to lowercase.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <wchar.h> #include <wctype.h> int main() { char *alpha = "abcdefghijklmnopqrstuvwxyz"; char *tocase[2] = {"toupper", "tolower"}; wchar_t *wcalpha; int i, j; size_t alphalen; alphalen = strlen(alpha)+1; wcalpha = (wchar_t *)malloc(sizeof(wchar_t)*alphalen); mbstowcs(wcalpha, alpha, 2*alphalen); for (i=0; i<2; ++i) { printf("Input string: %ls\n", wcalpha); for (j=0; j<strlen(alpha); ++j) { wcalpha[j] = (wchar_t)towctrans((wint_t)wcalpha[j], wctrans(tocase[i])); } printf("Output string: %ls\n", wcalpha); printf("\n"); } return 0; /**************** Output should be similar to: ****************** Input string: abcdefghijklmnopqrstuvwxyz Output string: ABCDEFGHIJKLMNOPQRSTUVWXYZ Input string: ABCDEFGHIJKLMNOPQRSTUVWXYZ Output string: abcdefghijklmnopqrstuvwxyz *******************************************************************/
Related Information
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.