How would I compare a char to see if it was up, down, left, or right?

Say I use getch(), and the person enters the up, down, left, or right key. How would I compare the variable (Let's say the variable is called 'Var') to see if it was one of those keys in an if statement?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//WINDOW *terminal;
keypad( terminal, true ); //functions keys (as arrows) have a single value representation
switch( getch() ){
case KEY_DOWN: 
	echochar( 'D' );
	break;
case KEY_UP: 
	echochar( 'U' );
	break;
case KEY_LEFT: 
	echochar( 'L' );
	break;
case KEY_RIGHT: 
	echochar( 'R' );
	break;
case ERR:
	echochar( 'E' );
	break;
default:
	echochar( 'Z' );
}
Last edited on
Topic archived. No new replies allowed.