Please tell me why the getche () function returns a negative integer value. The problem is that when you run code in Visual Studio, the function returns the correct positive values. But when I run the same code in C ++ Builder, the function returns negative values. Why is that? I type Russian characters from the keyboard. Thanks in advance for your help.

#pragma hdrstop #pragma argsused #ifdef _WIN32 #include <tchar.h> #else typedef char _TCHAR; #define _tmain main #endif #include <conio.h> #include <stdio.h> #include <iostream> #include <Windows.h> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { setlocale(LC_CTYPE, "rus"); SetConsoleOutputCP(1251); printf("Π’Π²Π΅Π΄iΡ‚ΡŒ рядок: "); //ΠΊΠΎΠ΄ΠΈ голосних символів const int SIZE = 20; int codes[] = { 224, 192, 229, 197, 179, 178, 232, 200, 175, 191, 238, 206, 211, 243, 255, 223, 170, 186, 222, 254 }; //Π»Ρ–Ρ‡ΠΈΠ»ΡŒΠ½ΠΈΠΊΠΈ int vovelsCounter = 0; int otherCounter = 0; int wordCounter = 0; //ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΊΠ° для Π²Π²ΠΎΠ΄Ρƒ SetConsoleCP(1251); for (;;) { int symbol = getche(); //якщо натиснули ESC Π²ΠΈΠΉΡ‚ΠΈ if (symbol == 13) break; //якщо натиснули ΠΏΡ€ΠΎΠ±Ρ–Π», Π·Π±Ρ–Π»ΡŒΡˆΠΈΡ‚ΠΈ Π»Ρ–Ρ‡ΠΈΠ»ΡŒΠ½ΠΈΠΊ слів Π½Π° ΠΎΠ΄ΠΈΠ½ΠΈΡ†ΡŽ else if (symbol == 32) { wordCounter++; } //якщо Π²Π²Π΅Π»ΠΈ приголосний, Π·Π±Ρ–Π»ΡŒΡˆΠΈΡ‚ΠΈ Π»Ρ–Ρ‡ΠΈΠ»ΡŒΠ½ΠΈΠΊ приголосних Π½Π° ΠΎΠ΄ΠΈΠ½ΠΈΡ†ΡŽ else if (symbol > 192 && symbol < 197 || symbol > 197 && symbol < 200 || symbol > 200 && symbol < 206 || symbol > 206 && symbol < 211 || symbol > 211 && symbol < 222 || symbol > 224 && symbol < 229 || symbol > 229 && symbol < 232 || symbol > 232 && symbol < 238 || symbol > 238 && symbol < 243 || symbol > 243 && symbol < 254) { otherCounter++; } //Π² Ρ–Π½ΡˆΠΎΠΌΡƒ Ρ€Π°Π·Ρ–, ΠΏΠ΅Ρ€Π΅Π²Ρ–Ρ€ΠΈΡ‚ΠΈ, Ρ‡ΠΈ Π±ΡƒΠ² Π²Π²Π΅Π΄Π΅Π½ΠΈΠΉ голосний, якщо Ρ‚Π°ΠΊ, Ρ‚ΠΎ Π·Π±Ρ–Π»ΡŒΡˆΡƒΠ΅ΠΌΠΎ значСння Π»Ρ–Ρ‡ΠΈΠ»ΡŒΠ½ΠΈΠΊΠ° голосних Π½Π° ΠΎΠ΄ΠΈΠ½ΠΈΡ†ΡŽ else { for (int i = 0; i < SIZE; i++) { if (symbol == codes[i]) { vovelsCounter++; break; } } } } SetConsoleOutputCP(1251); printf("\n\nГолосні: %d,\nΠŸΡ€ΠΈΠ³ΠΎΠ»ΠΎΡΠ½i: %d\nΠ‘Π»ΠΎΠ²Π°: %d\n", vovelsCounter, otherCounter, wordCounter + 1); system("pause"); return 0; } 
  • one
    Apparently, in C ++ Builder, the type char is signed, so you get negative values ​​for characters over 127th ... - Harry

0