Ncurses Library realizes electronic clock

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.