This shows you the differences between two versions of the page.
— |
c:stdlib.h:mbstowcs [2024/02/16 01:04] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ===== mbstowcs ===== | ||
+ | |||
+ | <code c> | ||
+ | #include <stdlib.h> | ||
+ | size_t mbstowcs(schar_t *pwcs, const char *str, size_t n); | ||
+ | </code> | ||
+ | ===== Description ===== | ||
+ | mbstowcs converts multibyte characters to wide characters | ||
+ | |||
+ | ===== mbstowcs c sourcecode example ===== | ||
+ | <code c> | ||
+ | /* | ||
+ | * mbstowcs example code | ||
+ | * http://code-reference.com/c/stdlib.h/mbstowcs | ||
+ | */ | ||
+ | #include <stdio.h> | ||
+ | #include <stdlib.h> | ||
+ | |||
+ | int main( void ) | ||
+ | { | ||
+ | char mbinput[8] = "\x54\x65\x73\x74\x20\x31\x32"; | ||
+ | wchar_t output[8]; | ||
+ | size_t wcssize; | ||
+ | |||
+ | wcssize = mbstowcs(output, mbinput, 8); | ||
+ | |||
+ | printf("mbstowcs returned %d\n", wcssize); | ||
+ | |||
+ | printf("output: 0x%.4x 0x%.4x 0x%.4x 0x%.4x 0x%.4x 0x%.4x 0x%.4x \n", | ||
+ | output[0], output[1], output[2], output[3], output[4], output[5], output[6], output[7]); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ==== output of mbstowcs example ==== | ||
+ | user@host:~/code-reference.com# .//mbstowcs2 | ||
+ | mbstowcs returned 7 | ||
+ | output: 0x0054 0x0065 0x0073 0x0074 0x0020 0x0031 0x0032 | ||