Turbo C에서 Getch ()는 무엇을 반환합니까?키를 누르면 ASCII 값이 아님을 확신합니다.
문제
Turbo C가 return의 getch ()는 무엇입니까?나는 프로그램의 화살표 키를 초기화하기 위해 사용했으며, Getch ()가 리턴 한 값은 ASCII 값이 아닌 알파벳에 대한 ASCII 값 인 77, 80, 72 및 75였습니다.그들이 ASCII 값이 아닌 경우, 그들은 무엇입니까?
해결책
they non-standard getch()
에 제공된 conio.h
는 int :
#include <conio.h>
int getch(void);
.
참조부터 :
A single character from the predefined standard input handle is read and returned.
The input is not buffered. If there is a character pending from ungetch
(see section ungetch), it is returned instead. The character is not echoed to the
screen. This function doesn't check for special characters like Ctrl-C.
If the standard input handle is connected to the console, any pending output in the
stdout and stderr streams is flushed before reading the input, if these streams are
connected to the console.
Return Value
The character.
Portability
ANSI/ISO C No
POSIX No
.
화살표 키의 문제는 가 싱글 바이트 문자가 아닌 이라는 것입니다.화살표 키를 처리하려면 멀티 바이트 코드를 처리해야합니다.받는 숫자는 단순히 키 코드의 두 바이트 중 하나입니다.
다른 팁
getch () 함수 화살표 키 (및 다른 특수 키)에 대한 두 개의 키 코드를 반환하고 0 (0x00) 또는 224 (0xe0) 먼저 반환 한 다음 눌린 키를 식별하는 코드를 반환합니다. 화살표 키의 경우 먼저 224를 반환하고 72 (up), 80 (아래), 75 (왼쪽) 및 77 (오른쪽)을 반환합니다.Num-Pad 화살표 키 (NumLock OFF)를 누르면 Getch ()는 224 대신에 먼저 0을 반환합니다.
그래서, 당신은 다음과 같은 일을 할 수 있습니다 :
char ch = getch ();
if (ch == 0 || ch == 224)
{
switch (getch ())
{
case 72:
/* Code for up arrow handling */
break;
case 80:
/* Code for down arrow handling */
break;
/* ... etc ... */
}
}
.
getch ()는 어떤 식 으로든 표준화되지 않으며 이러한 코드는 컴파일러에서 컴파일러마다 다를 수 있습니다.
제휴하지 않습니다 StackOverflow