Please help me solve the problem. In a C ++ program for Linux, you need to alternately open text files whose name begins with a Cyrillic letter, and ends with a Latin alphabet. Well, for example, first u.txt, and then l.txt. But since the Russian letter occupies 2 bytes, there is a problem with combining it in the same line with the Latin ones, which weigh 1 byte each. The option to create a string with simultaneous initialization, for example char word[] = "ю.txt"
works. But I have more than 30 such files. I do not consider it appropriate to declare so many variables. Therefore, in the cycle I alternately change word [0] to the desired Russian letter. And that's where everything collapses. Because in place of one Russian letter another Russian is not correctly recorded.
- And the source is? - alexlz
|
1 answer
Write all Russian letters in one line.
char *b="абвгдежзийклмнопрстуфхцчшщъыьэюя";
and copy from this array
memcpy(word, b+i*2, 2);
Another option is to see how utf-8 works:
$ od -t x1 абвгдеёжзийклмнопрстуфхцчшщъыьэюя 0000000 d0 b0 d0 b1 d0 b2 d0 b3 d0 b4 d0 b5 d1 91 d0 b6 0000020 d0 b7 d0 b8 d0 b9 d0 ba d0 bb d0 bc d0 bd d0 be 0000040 d0 bf d1 80 d1 81 d1 82 d1 83 d1 84 d1 85 d1 86 0000060 d1 87 d1 88 d1 89 d1 8a d1 8b d1 8c d1 8d d1 8e 0000100 d1 8f 0a
The first byte is the oldest, it increases when the second should reach 0xc0
|