Chapter 27 . (Christian web host) Programming Environments and Interfaces 713

Chapter 27 . Programming Environments and Interfaces 713 /* start ncurses */ initscr(); /* draw a purty border */ box(stdscr, ACS_VLINE, ACS_HLINE); mvwaddstr(stdscr, 1, 1, INPUT: ); refresh(); /* read characters until newline read */ noecho(); while ((c = getch()) != n ) { ++i; getyx(stdscr, y, x); /* at the right margin */ if (x == 79) { mvaddch(y + 1, 1, c); } else { waddch(stdscr, c); } waddch(stdscr, c); refresh(); } echo(); refresh(); /* print the character count */ getmaxyx(stdscr, maxy, maxx); mvwprintw(stdscr, maxy - 2, 1, characters read: %dn , i + 1); curs_set(0); refresh(); /* time to look at the screen */ sleep(3); /* shutdown ncurses */ endwin(); return 0; } One of the first things you notice is that nreadkey.c is about twice as long as readkey.c. The additional code is due entirely to the need to make sure the screen is set up, the cursor positioned appropriately, and so forth. To see if the additional code is worth it, compile nreadkey.c using the following command: $ gcc nreadkey.c -lncurses -o nreadkey To run the program, type ./nreadkey. Figure 27-5 shows the result after typing the same text as typed for readkey.c earlier.
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Leave a Reply