Advertisement
quantumech

Untitled

Aug 9th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. /**
  2.  * This example initializes NCurses, gets user input and prints user input to the center of the screen.
  3.  */
  4.  
  5. #include <curses.h>
  6. #include <stdlib.h>
  7.  
  8. int main()
  9. {
  10.     // Initialize NCurses
  11.     initscr();
  12.  
  13.     // Get width and height of console window
  14.     int winWidth, winHeight;
  15.     getmaxyx(stdscr, winHeight, winWidth);
  16.  
  17.     // Prompt user for input
  18.     printw("Please input some text: ");
  19.    
  20.     // Get input from user
  21.     // (getstr() automatically calls refresh())
  22.     char* input = malloc(128);
  23.     getstr(input);
  24.  
  25.     // Print user input to the center of the screen
  26.     move(winHeight / 2, winWidth / 2);
  27.     printw("%s", input);
  28.  
  29.     // Refresh screen so printed text shows
  30.     // PRINTW WILL NOT SHOW ANYTHING UNLESS refresh() IS CALLED
  31.     refresh();
  32.    
  33.     // Pause program until the user presses a key
  34.     getch();
  35.  
  36.     // De-initialize NCurses
  37.     endwin();
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement