#include #include #include #include #define LEN 5 int main() { char readInByte[LEN], writeOutByte[LEN]; // holds the character bytes const char *readInByteP[] = {readInByte}; // help pointer wchar_t readInWC[LEN], writeOutWC[LEN]; // holds the wide characters const wchar_t *writeOutWCP[] = {writeOutWC}; // help pointer wctrans_t wctransDesc; // holds the descriptor for conversion int i, ret; const char myLocale[] = "ja_JP.utf8"; char *localeSet; readInByte[0] = 0xc3; readInByte[1] = 0x84; // german umlaut A (upper) in UTF-8 readInByte[2] = 0xc3; readInByte[3] = 0xa4; // german umlaut a (lower) in UTF-8 readInByte[4] = 0; // print out the input printf("german umlaut A (upper) UTF-8: %hhx %hhx\n", readInByte[0], readInByte[1]); printf("german umlaut a (lower) UTF-8: %hhx %hhx\n", readInByte[2], readInByte[3]); if((localeSet = setlocale(LC_CTYPE, myLocale)) == NULL) { perror("setlocale"); exit(1); } else printf("locale set: %s\n", localeSet); ret = mbsrtowcs(readInWC, readInByteP, LEN, NULL); // convert bytes to wide chars printf("number of wide chars: %i\n", ret); wctransDesc = wctrans("tolower"); // get descriptor for wc operation if(wctransDesc == 0) { perror("wctransDesc"); exit(1); } // make the transformation according to descriptor i=0; while((writeOutWC[i] = towctrans(readInWC[i], wctransDesc)) != L'\0') i++; ret = wcsrtombs(writeOutByte, writeOutWCP, LEN, NULL); // convert wide chars to bytes printf("number of bytes: %i\n", ret); // print out the result printf("german umlaut A tolower(): %hhx %hhx\n", writeOutByte[0], writeOutByte[1]); printf("german umlaut a tolower(): %hhx %hhx\n", writeOutByte[2], writeOutByte[3]); return 0; }