In ncurses,Scan codes for function keys,Esc etc have been defined with values greater than 256 (U cant use char variable to capture them).
To get ur program right , change the contition as

...