1. Create GRAPHICS.C
2. Edit GRAPHICS.C, compile:
Gcc-o graphic graphic.c-l/usr/lib/i386-linux-gnu/-lncurses
The source code of 3.GRAPHICS.C is as follows:
[email protected]:/mnt/shared/appbox/graphic# cat graphic.c#include <curses.h> #include <stdio.h># Include <stdlib.h> #include <unistd.h> #include <string.h> #include <ncurses.h> #include < unistd.h> #include <time.h> #include <string.h> #include <stdlib.h> #include <pthread.h># Include <errno.h>int main () {int x, y; Gets the number of rows and columns of the current standard window time_t t; pthread_t thread; WINDOW *win; INITSCR (); Initialize standard window, must drop Curs_set (0); Hide cursor dynamic noecho (); Input no echo getmaxyx (stdscr,y,x); Gets the number of rows and columns of the standard window Win=newwin (5,40,Y/2-5/2,X/2-40/2); Create a window in the center of the standard window refresh (); Refresh the standard window, or you will not be able to display the newly created window Wrefresh (win); Refresh the newly created window Getmaxyx (win,y,x); Gets the number of rows and columns of the new window while (1)//infinite loop {t=time (NULL); Get all the seconds from a certain time to now MVWPRINTW (WIN,Y/2,X/10, "["); Enter the date and time at the center of the new window using the CTime function to convert MVWPRINTW (win,y/2,x/2-(strlen (CTime (&t)) +1)/2, "%s ", CTime (&t)); Enter the date and time at the center of the newly created window using the CTime function to convert mvwprintw (WIN,Y/2,4*X/5, "]"); Enter the date and time in the center of the newly created window using the CTime function to convert Wrefresh (win); Refresh the window, or you will not be able to display the date and time sleep (1); Suspend one second} endwin (); return 0;} [email protected]:/mnt/shared/appbox/graphic#
4. The output is as follows:
[Fri Dec 26 10:18:45 2014]
Ncurses Library realizes electronic clock