I need some help. I'm writing a program that opens 2 source files in UTF-8 encoding without BOM. The first contains English text and some other information, including ID. The second contains only string ID and translation. The program changes every string from the first file by replacing English chars to Russian translation from the second one and writes these strings to output file. Everything seems to be ok, but there is BOM appears in destination file. And i want to create file without BOM, like source. I open files with fopen function in text mode with ccs=UTF-8 read string with fgetws function to wchar_t buffer and write with fputws function to output file
Asked
Active
Viewed 711 times
1
-
Which language? Must be one from Microsoft... – wildplasser Mar 27 '16 at 22:17
-
@wildplasser, the C language – Артём Янкин Mar 27 '16 at 22:18
-
show the code, are we expected to debug a run time problem by guessing? – user3629249 Mar 29 '16 at 00:49
2 Answers
5
Don't use text mode, don't use the MS ccs=
extension to fopen
, and don't use fputws
. Instead use fopen
in binary mode and write the correct UTF-8 yourself.

R.. GitHub STOP HELPING ICE
- 208,859
- 35
- 376
- 711
0
For a new file, there is no way to stop the the byte order mark from being created. However, you can immediately rewind after creating the file. Output will be UTF8 encoded without BOM.
FILE* fp = NULL;
_wfopen_s(&fp, sfn, L"wt, ccs=UTF-8");
fseek(fp, 0L, SEEK_SET); // rewind to overwrite EF BB BF (UTF-8 BOM)

Richard Frank
- 21
- 5