This blog is under construction

Tuesday, 10 September 2013

closegraph example in c

Header file:
    graphics.h

Synopsis:
     void closegraph (void);

Description:
      closegraph() closes the graphic screen and deallocates memory allocated for the graphic screen.


closegraph function in c graphics



  #include <graphics.h>
  #include <stdlib.h>
  #include <stdio.h>
  #include <conio.h>

  int main(void) {
        /* request auto detection */
        int graphicDriver = DETECT, graphicMode;
        int err, x, y;

        clrscr();
        printf("We are in Text Mode now!!\n");
        printf("Enter any key to enter graphical mode:");
        getch();

        /* initialize graphics mode */
        initgraph(&graphicDriver,
                &graphicMode, "C:/TURBOC3/BGI");

        /* read result of initialization */
        err = graphresult();

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

        /* clears graphic screen */
        cleardevice();

        /* mid position in x and y-axis */
        x = getmaxx() / 2;
        y = getmaxy() / 2;

        /* draws a circle */
        circle(x, y, 100);

        /* output a message */
        outtextxy(0, y + 200, "Press a key to exit Graphic mode:");

        /* wait for a key */
        getch();

        /* shut down the graphics system */
        closegraph();

        printf("Entered text mode again!!\n");
        printf("Press any key to exit:");
        getch();
        return 0;
  }




Output: (closegraph built-in function in c graphics.h)


1 comment: