This blog is under construction

Wednesday, 4 September 2013

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;
  }




Output: (c program to implement digital clock)





1 comment:

  1. can you please help me...? I want to become a great programmer, even though Im too young.. give me a tutorial for all of your knowledge about programming.. thanks.. :)

    ReplyDelete