This blog is under construction

Thursday 12 September 2013

moveto example in c

Header file:
    graphics.h

Synopsis:
      void moveto (int x, int y);
     
Description:
     moveto() moves the current postion(CP) to (x, y).


moveto function in c graphics



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

  int main(void) {
        /* request auto detection */
        int graphicDriver = DETECT, graphicMode;
        int i, err, x, y;
        char str[80];

        /* initialize graphics and local variables */
        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;
        }

        /* mid position in x and y-axis */
        x = y = 0;

        for (i = 1; i <= 18; i++) {
                /* moves current position to given position(x, y) */
                moveto(x, y);

                sprintf(str, "(%d, %d) - Current position", x, y);

                /* prints the given string */
                outtext(str);

                /* advance the position */
                x = x + 25;
                y = y + 25;
                getch();
        }

        /* clean up */
        getch();
        closegraph();
        return 0;
  }





Output: (moveto built-in function in c graphic.h)


No comments:

Post a Comment