For special function keys, getch()
doesn't necessarily return the ASCII character, it returns one of the KEY_xxx
codes in <curses.h>
. In the case of Backspace, this is:
#define KEY_BACKSPACE 0407 /* backspace key */
Since you declare ch
as char
rather than int
, the value 0407
is being truncated to 07
.
Change the declaration to:
int ch;
and then it will display 263
when you press Backspace. addch()
will still display ^G
, though, because it doesn't use the KEY_xxx
macros. You need to handle these characters in your code.