简体   繁体   中英

My C program writes hello, world in Chinese but all I get for output is a blank line

I am trying to learn how to use non-ascii (ie, wide) characters in my C programs.

I figured that I would start with a C program that writes hello, world in Chinese.

Below is my program. It compiles fine but when I run it (from a Windows command line) I just get a blank line. I am thinking that either (a) my program is not correct, or (b) I have to do something to my Windows command screen for it to display Chinese. Do you know which is the case?

#include <wchar.h>

int main()
{
    wchar_t *helloworld = L"你好,世界";
    wprintf_s(L"%s\n", helloworld);
    return 0;
}

For long strings you have to use %S as opposed to %s.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM