Untitled

 avatar
unknown
plain_text
2 years ago
1.5 kB
4
Indexable
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<wchar.h>
#include<locale.h>
#include<windows.h>
#include<string.h>
#include<io.h>
//#include<wcntl.h>
int main() {
    char str2[128]; // оригинальная обычная 8байтовая строка из файла
    wchar_t str1[128]; //  широкая строка с клавиатуры 
    wchar_t str2c[128]; // строка один из фалйа переведенная в широкий формат
    wchar_t str_res[256] = L"";
    char* ptr2 = NULL;
    wchar_t* ptr1 = NULL;
    wchar_t* ptr2c = NULL;

    FILE* fin = fopen("input.txt", "rt,ccs =UTF-8");
    FILE* fout = fopen("output.txt", "wt, ccs = UTF-16LE");

    if (!fin || !fout) {
        exit(1);
    }
    setlocale(LC_ALL, "rus");
    SetConsoleCP(1251);
    _setmode(_fileno(stdout), 0x00020000);

    ptr2 = fgets(str2, 40, fin);
    *(ptr2 + strlen(ptr2) - 1) = L'\0';

    ptr1 = fgetws(str1, 40, stdin); // str2c - char, ptr2c - wchar
    *(ptr1 + wcslen(ptr1) - 1) = '\0';

    mbstowcs(str2c, str2, 40); // мы из обычной строки делаем широкую
    ptr2c = str2c;

    if (wcslen(ptr1) > wcslen(ptr2c)) {
        wcscat(str_res, ptr1);
        wcscat(str_res, ptr2c);
    }
    else {
        wcscat(str_res, ptr2c);
        wcscat(str_res, ptr1);
    }
    wprintf(L"%s\n", str_res);
    fwprintf(fout, L"%s\n", str_res);
    fclose(fin);
    fclose(fout);
    return 0;
}
Editor is loading...
Leave a Comment