wctrans() — Get Handle for Character Mapping
Format
#include <wctype.h>
wctrans_t wctrans(const char *property);
Language Level
ANSI
Threadsafe
Yes
Description
The wctrans()
function
returns a value with type wctrans_t. This value describes a mapping
between wide characters. The string argument property is a
wide character mapping name. The wctrans_t equivalent of the wide
character mapping name is returned by this function. The toupper and tolower wide
character mapping names are defined in all locales.
Return Value
If property is a valid wide
character mapping name, the wctrans()
function
returns a nonzero value that is valid as the second argument to the towctrans()
function.
Otherwise, it returns 0.
Example
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
*******************************************************************/