These functions read a single character from the terminal. But there are several subtle facts to consider. For example if you don't use the function cbreak(), curses will not read your input characters contiguously but will begin read them only after a new line or an EOF is encountered. In order to avoid this, the cbreak() function must used so that characters are immediately available to your program. Another widely used function is noecho(). As the name suggests, when this function is set (used), the characters that are keyed in by the user will not show up on the screen. The two functions cbreak() and noecho() are typical examples of key management. Functions of this genre are explained in the key management section .
Example 4. A Simple scanw example
/* File path: basics/scanw_example.c */ #include <ncurses.h> /* ncurses.h includes stdio.h */ #include <string.h> int main() { char mesg[]="Enter a string: "; /* message to be appeared on the screen */ char str[80]; int row,col; /* to store the number of rows and * * the number of columns of the screen */ initscr(); /* start the curses mode */ getmaxyx(stdscr,row,col); /* get the number of rows and columns */ mvprintw(row/2,(col-strlen(mesg))/2,"%s",mesg); /* print the message at the center of the screen */ getstr(str); mvprintw(23, 0, "You Entered: %s", str); getch(); endwin(); return 0; } |