Last active
March 26, 2017 18:10
-
-
Save zelinskiy/4f6aec60c0bd2d27c8e0c905f25e4587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <tchar.h> | |
#include <locale.h> | |
#include <windows.h> | |
#include <algorithm> | |
#include <iterator> | |
#include <vector> | |
using namespace std; | |
#ifdef UNICODE | |
typedef wchar_t TCHAR; | |
#define TEXT(a) L##a | |
#else | |
typedef char TCHAR; | |
#define TEXT(a) a | |
#endif | |
int compare(const void *a, const void *b) | |
{ | |
return wcscmp((const wchar_t*)a, (const wchar_t*)b); | |
} | |
int main(int argc, _TCHAR* argv[]) | |
{ | |
//VARIABLES | |
const int l = 5; | |
const int ma = 20; | |
TCHAR fio[l][ma] = { | |
TEXT("Льюис Керолл"), | |
TEXT("САБАКА"), | |
TEXT("СОС"), | |
TEXT("Какой то чел"), | |
TEXT("Славой Жижек") | |
}; | |
wchar_t ufio[l][ma]; | |
char ansii[l][ma]; | |
int b; | |
_tsetlocale(LC_ALL, _T("Russian")); | |
SetConsoleCP(1251); | |
SetConsoleOutputCP(1251); | |
//1 | |
printf("\nTASK 1\n"); | |
if (sizeof(TCHAR) == 1) | |
{ | |
printf("ANSI \n"); | |
} | |
else | |
{ | |
printf("Unicode \n"); | |
} | |
//5 | |
printf("\nTASK 5\n"); | |
for (int i = 0; i<l; i++) | |
{ | |
_tprintf(_T("%s\n"), fio[i]); | |
} | |
//6 | |
printf("\nTASK 6\n"); | |
#ifdef UNICODE | |
for (int i = 0; i < l; i++) { | |
for (int j = 0; j < ma; j++) { | |
ufio[i][j] = fio[i][j]; | |
} | |
} | |
#else | |
for (int i = 0; i < l; i++) | |
{ | |
b = MultiByteToWideChar(CP_ACP, 0, fio[i], -1, 0, 0); | |
MultiByteToWideChar(CP_ACP, 0, fio[i], -1, ufio[i], b); | |
} | |
#endif | |
//7 | |
printf("\nTASK 7\n"); | |
for (int i = 0; i<l; i++) | |
{ | |
printf("wprintf:\n"); | |
wprintf(L"%s\n", ufio[i]); | |
printf("printf:\n"); | |
printf("%S\n", ufio[i]); | |
#ifdef UNICODE | |
printf("MessageBox:\n"); | |
MessageBox(0, ufio[i], TEXT("Names"), MB_OK); | |
#endif | |
} | |
//8 | |
printf("\nTASK 8\n"); | |
qsort(ufio, l, ma*sizeof(wchar_t), compare); | |
for (int i = 0; i < l; i++) | |
{ | |
wprintf(L"%s\n", ufio[i]); | |
} | |
//9 | |
wprintf(L"\nTASK 9\n"); | |
for (int i = 0; i < l; i++) | |
{ | |
int b = WideCharToMultiByte(CP_ACP, 0, ufio[i], -1, 0, 0, 0, NULL); | |
WideCharToMultiByte(CP_ACP, 0, ufio[i], -1, ansii[i], b, 0, 0); | |
} | |
//10 | |
wprintf(L"\nTASK 10\n"); | |
for (int i = 0; i < l; i++) { | |
printf("%s\n", ansii[i]); | |
} | |
system("Pause"); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment