getch()
is a function found on Windows in #include <conio.h>
or on Unix in #include <curses.h>
. Did you mean to call one of those? It is not a function defined in the C standard (the standard functions are getc()
and getchar()
, of course). If you use the function from <curses.h>
, you need to do some initialization first and finalization afterwards.
Assuming you resolve the issue of which function you are planning to call, then you would find that the control characters are number 1..26:
- Control-A =
1
- Control-Z =
26
You might need to do some translation work on getch()
from <curses.h>
— it returns interesting values for function keys and other special key strokes and might not return what you expect for the control keys.
Also, your terminal driver may confuse you by interpreting various characters for you (especially if you use getchar()
or getc()
). For example, Control-D will likely be treated as EOF; Control-H is likely to be the backspace or erase; Control-C is likely to be the interrupt; and Control-Z is likely to be 'suspend' (meaning 'return to the shell without exiting the current program — just suspend it pro tem'). Other control keys have other meanings. You can often get the 'genuine' meaning by typing Control-VControl-Z, for example — using the Control-V to suppress the special meaning of the next character.