简体   繁体   English

如何使用ansi编码在c中创建文件

[英]How to create file in c with ansi encoding

How can I create file in C (not C++ or C#) with ANSI encoding?如何使用 ANSI 编码在 C(不是 C++ 或 C#)中创建文件?

When I create txt file by this code:当我通过这段代码创建 txt 文件时:

FILE* file_ptr;
file_ptr = fopen("new filler.txt", "r");

It creates file with UTF-8 encoding.它使用 UTF-8 编码创建文件。 How can I fix that automatically?我怎样才能自动修复它?

If you open the file in binary mode, there is no encoding at all and you are free to control every byte that goes into the file.如果以二进制模式打开文件,则根本没有编码,您可以自由控制进入文件的每个字节。

FILE * const f = fopen("myansi.txt", "wb");
fputs("\033+", f);
fclose(f);

The above puts the ANSI.SYS sequence for clearing the screen into the file.上面将用于清除屏幕的ANSI.SYS序列放入文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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