digital clock using graphics

C program to implement digital clock using graphics

Implement Digital Clock Using C Graphics

  #include <stdio.h>
  #include <conio.h>
  #include <graphics.h>
  #include <time.h>
  #include <dos.h>
  #include <string.h>

  int main() {
        /* request auto detection */
        int gdriver = DETECT, gmode;
        int midx, midy, err;
        long mytime;
        char date[256];

        /* initialize graphic mode */
        initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");
        err = graphresult();

        if (err != 0) {
                /* error occurred */
                printf("Graphics Error: %s\n",
                                grapherrormsg(err));
                return 0;
        }

        /* mid positions in x and y axis */
        midx = getmaxx() / 2;
        midy = getmaxy() / 2;


        /* mid positions in x and y axis */
        midx = getmaxx() / 2;
        midy = getmaxy() / 2;

        while (!kbhit()) {
                /* clears graphic screen */
                cleardevice();

                /* get time in seconds */
                mytime = time(NULL);

                /* store the date and time in the given string */
                strcpy(date, ctime(&mytime));

                settextjustify(CENTER_TEXT, CENTER_TEXT);
                settextstyle(TRIPLEX_FONT, HORIZ_DIR, 3);

                /* locate the postion to write */
                moveto(midx, midy);

                /* print the date and time */
                outtext(date);

                /* sleep for a second */
                sleep(1);
        }

        getch();

        /* deallocate memory allocated for graphic screen */
        closegraph();
        return 0;
  }

1 comment:

  1. This article was written by a real thinking writer. I agree many of the with the solid points made by the writer. I’ll be back.
    list to string in python

    ReplyDelete