Home > Back-end >  Why can not output Chinese characters above procedure, please
Why can not output Chinese characters above procedure, please

Time:05-12

#include
#include
#include

Int main (void) {
Int dat=0;
While (1) {
Dat=getch ();
//printf (" % d \ n \ n ", dat);
Printf (" % c % c ", ((dat& 0 xff00) & gt;> 8), (dat& 0 x00ff));
}
system("pause");
return 1;
}

Why can not output Chinese characters above procedure, please

CodePudding user response:

Because getch () returns the corresponding GBK Chinese characters or UTF8 or Unicode,

CodePudding user response:

Chinese characters is not accounted for 1 byte characters (can know a man of a few bytes), the getch returns an int as getchar () returns an int is the same truth: type of ascension;

So if you want to output the man, it is recommended that the string;

CodePudding user response:

Getwchar can return characters

CodePudding user response:

I hope it can help you, looking forward to adopt: https://blog.csdn.net/it_xiangqiang/category_10581430.html

CodePudding user response:

Processing of Chinese characters is a complex topic, but for you the program, and is not too difficult,
 # include & lt; Stdio. H> 

Int main (void)
{
Char [2048] b={0};
C, int x=0;

While ((c=getchar ())! B=(EOF) [x + +]=c;

The printf (b);
}

Getchar () function only reads one byte at a time, and then extended to the int type, so, our task is to store the bytes read and in turn, the benefits of this program is not considering the operating system actually use the execution character set, because of the character encoding that was sent to the program and the system output (i.e., operating system interface part of the internal call printf) using a character encoding scheme is always consistent,
  • Related