1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE* src = fopen("input.txt", "rb");
if(!src) return 0;
FILE* dst = fopen("output.txt", "wb");
if(!dst) return 0;
fseek(src, 0, SEEK_END);
long filesize = ftell(src);
char *ansi = malloc(filesize);
fseek(src, 0, SEEK_SET);
fread(ansi, 1, filesize, src);
int codepage = CP_ACP;
int u16size = MultiByteToWideChar(codepage, 0, ansi, filesize, NULL, 0);
wchar_t *u16 = malloc(u16size * sizeof(wchar_t));
MultiByteToWideChar(codepage, 0, ansi, filesize, u16, u16size);
int u8size = WideCharToMultiByte(CP_UTF8, 0, u16, u16size, NULL, 0, NULL, FALSE);
char *u8 = malloc(u8size);
WideCharToMultiByte(CP_UTF8, 0, u16, u16size, u8, u8size, NULL, FALSE);
fwrite(u8, 1, u8size, dst);
return 0;
}
| |