Debian Codegraph @

test/testu16.c

raw
1 #include <stdio.h>
2 #include <windows.h>
3 #include <fcntl.h>
4 #include <io.h>
5
6 /* This program demonstrates Unicode UTF-16 printed text redirected to a
7 correct UTF-16 file.
8
9 .\testu16.exe > out.txt
10
11 */
12
13 int main () {
14
15 int prevmode;
16
17
18 prevmode = _setmode(_fileno(stdout), _O_U16TEXT);
19 /* We need to print an UTF-16 BOM for correct redirection in PowerShell. */
20 fwprintf(stdout, L"\xfeff");
21 fwprintf(stdout,L"one\n");
22 fwprintf(stdout,L"two\n");
23 fwprintf(stdout,L"three\n");
24 /* Flushing stdout is required to get correct UTF-16.
25 This is required for both CMD.exe and PowerShell. */
26 fflush(stdout);
27 _setmode(_fileno(stdout), prevmode);
28
29
30 return 0;
31 }