Source Code File 08-04_secretkey
08-04_secretkey.c
#include <ncurses.h> int main() { int key1,key2; initscr(); addstr("Type a key: "); refresh(); key1 = getch(); clear(); addstr("Type the same key: "); noecho(); key2 = getch(); move(1,0); if( key1 == key2 ) addstr("The keys match"); else addstr("The keys don't match"); refresh(); getch(); endwin(); return(0); }
Output Screenshot
(Click to cycle images.)
Notes
* Yes, another silly program. Yet, the noecho() function has uses in many programs to suppress direct text output that would otherwise mess with screen presentation. Especially if you're using a "press any key" type of function, it's beneficial to suppress text output from the getch() function.
Copyright © 1997-2024 by QPBC.
All rights reserved