how to write unicode hello world in C on windows
- by hatchetman82
im tyring to get this to work:
#define UNICODE
#define _UNICODE
#include <wchar.h>
int main()
{
wprintf(L"Hello World!\n");
wprintf(L"£?, ?, ?!\n");
return 0;
}
using visual studio 2008 express (on windows xp, if it matters).
when i run this from the command prompt (started as cmd /u which is supposed to enable unicode ?) i get this:
C:\dev\unicodevs\unicodevs\Debugunicodevs.exe
Hello World!
-ú8
C:\dev\unicodevs\unicodevs\Debug
which i suppose was to be expected given that the terminal does not have the font to render those.
but what gets me is that even if i try this:
C:\dev\unicodevs\unicodevs\Debugcmd /u /c "unicodevs.exe output.txt"
the file produced (even though its UTF-8 encoded) looks like:
Hello World!
壓
the source file itself is defined as unicode (encoded in UTF-8 without BOM).
the compiler output when building:
1------ Rebuild All started: Project: unicodevs, Configuration: Debug Win32 ------
1Deleting intermediate and output files for project 'unicodevs', configuration 'Debug|Win32'
1Compiling...
1main.c
1.\main.c(1) : warning C4005: 'UNICODE' : macro redefinition
1 command-line arguments : see previous definition of 'UNICODE'
1.\main.c(2) : warning C4005: '_UNICODE' : macro redefinition
1 command-line arguments : see previous definition of '_UNICODE'
1Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\wchar.h
1Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\sal.h
1C:\Program Files\Microsoft Visual Studio 9.0\VC\include\sal.h(108) : warning C4001: nonstandard extension 'single line comment' was used
1Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtassem.h
1Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\vadefs.h
1Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\swprintf.inl
1Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\wtime.inl
1Linking...
1Embedding manifest...
1Creating browse information file...
1Microsoft Browse Information Maintenance Utility Version 9.00.30729
1Copyright (C) Microsoft Corporation. All rights reserved.
1Build log was saved at "file://c:\dev\unicodevs\unicodevs\unicodevs\Debug\BuildLog.htm"
1unicodevs - 0 error(s), 3 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
any ideas on what am i doing wrong ?
similar questions on ST (like this one: http://stackoverflow.com/questions/787589/unicode-hello-world-for-c) seem to refer to *nix builds - as far as i understand setlocale() is not available for windows.
i also tried building this using code::blocks/mingw gcc, but got the same results.