It is necessary in the string UNICODE to write all the characters in reverse order. Very little experience with UNICODE therefore I don’t understand what needs to be fixed.

#include "stdafx.h" #include <fcntl.h> #include <io.h> #include <cstdlib> #include <iostream> #include <stdio.h> #include "stdafx.h" int main() { wchar_t string[] = L"\x0124\x0117\x0177 \x263A\n"; int lenght = size_t wcslen (string); int temp, i, j; for (i = 0; j = lenght - 1; i < j; i++; j--) { temp = string[i]; string[i] = string[j]; string[j] = temp; } wprintf(string); system("pause"); return 0; } 

Closed due to the fact that off-topic participants 0xdb , user192664, Let's say Pie , Kromster , iksuy 29 Oct '18 at 14:44 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - 0xdb, Community Spirit, Let's say Pie, Kromster, iksuy
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    Duplicate question: C ++ - using UNICODE - andreymal
  • What you can not do? Immediately everything is very simple. - lpsat
  • I do not understand how to correct the error in the code and whether it is correct in general - Quest

1 answer 1

Working with UNICODE is no different from working with ANSI characters. The differences are minimal:

  1. Instead of char , wchar_t used (under Windows, WCHAR possible),
  2. UNICODE strings L"..." are used instead of the strings "..."
  3. UNICODE versions of string functions are used, for example, wcslen instead of strlen .

This is all you need to do to convert the program to work with unicode strings.

As for your program, you should not pay attention to what the compiler writes to you. Syntax errors are the easiest, just read the compiler messages. For example:

 int lenght = size_t wcslen (string); 

error, size_t not clear what. If you wanted to convert the wcslen result to lenght , you would have to write this:

 int lenght = (int)wcslen (string); 

Farther:

 for (i = 0; j = lenght - 1; i < j; i++; j--) 

The for loop must contain three expressions separated by semicolons. You have five. You probably wanted to write like this:

 for (i = 0, j = lenght - 1; i < j; i++, j--) 

For you, a comma may differ slightly from a semicolon, but for a compiler these are completely different things. He is not trying to guess what you meant, just notes it as a mistake.

The rest seems to be correct.