Logo  

CS256 - Fundamentals of Structured Programming

Displaying ./code/curses/intro-curses.c

#include <curses.h>
#include <string.h>

// Compile:
// gcc -o intro-curses intro-curses.c -lncurses

int main(void)
{
  // Starts curses:
  initscr();

  // Define a message and its "width" with strlen:  
  char mesg[] = "Hello, world!";
  int len = strlen(mesg);

  // Move the cursor to the middle of the screen (minus half the width of the
  // message) and print the message:
  mvprintw(LINES/2, COLS-len/2,"%s", mesg);
  // Make the real screen look like the virtual one:
  refresh();

  move(LINES-1,0);
  printw("Press any key to exit.");
  // Wait for the user to press a key:
  getch();

  // Shutdown curses:
  endwin();
  return 0;
}