Untitled
unknown
c_cpp
2 years ago
1.3 kB
5
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 str1[128]; wchar_t str2[128]; wchar_t str2c[128]; wchar_t str_res[256] = L""; char* ptr1 = NULL; wchar_t* ptr2 = NULL; wchar_t* ptr2c = NULL; FILE* fin = fopen("input2.txt", "rt,ccs =UTF-16LE"); FILE* fout = fopen("output.txt", "wt, ccs = UTF-16LE"); if (!fin || !fout) { exit(1); } setlocale(LC_ALL, "rus"); SetConsoleCP(1251); _setmode(_fileno(stdout), 0x00020000); ptr1 = fgets(str1, 40, fin); *(ptr1 + strlen(ptr1) - 1) = L'\0'; ptr2c = fgetws(str2c, 40, stdin); // str2c - char, ptr2c - wchar *(ptr2c + wcslen(ptr2c) - 1) = '\0'; mbstowcs(str2, str1, 40); // мы из обычной строки делаем широкую ptr2 = str2; if (wcslen(ptr1) > wcslen(ptr2)) { wcscat(str_res, ptr1); wcscat(str_res, ptr2); } else { wcscat(str_res, ptr2); 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