Home >Backend Development >C#.Net Tutorial >How to write Chinese in C language
Outputting Chinese in C language requires the following steps: Encode the source code file into UTF-8. Use the setlocale() function to set the locale: setlocale(LC_ALL, ""); use the printf() function to output Chinese, which requires a UTF-8 encoded string as a parameter.
How to output Chinese in C language
If you want to output Chinese in C language, you need to perform the following steps :
Use the setlocale()
function to set the locale : setlocale()
The function sets the locale of the program. For Chinese output, you need to use the following code:
<code class="c">setlocale(LC_ALL, "");</code>
Use printf()
function to output Chinese :
Use printf ()
When the function outputs Chinese, you need to use the %s
placeholder in the format string and take the UTF-8 encoded string as a parameter. For example:
<code class="c">printf("你好,世界!\n");</code>
Sample code:
<code class="c">#include <stdio.h> #include <locale.h> int main() { // 设置语言环境 setlocale(LC_ALL, ""); // 输出中文 printf("你好,世界!\n"); return 0; }</code>
The above is the detailed content of How to write Chinese in C language. For more information, please follow other related articles on the PHP Chinese website!