This blog is under construction

Thursday 12 September 2013

getx example in c

Header file:
    graphics.h

Synopsis:
      int getx (void);
     
Description:
     getx () returns x-coordinate of current graphics position.


getx 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 err, midx, midy;
        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));
                getch();
                return 0;
        }

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

        /* move to the screen center point */
        moveto(midx, midy);

        /* create a message string */
        sprintf(str, "current position(x, y) "
                        "<=> (%d, %d)", getx(), gety());

        /* setting the current drawing color */
        setcolor(12);

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

        /* moving current graphic position to (100, 100) */
        moveto(100, 100);
        strcpy(str, "Position (x, y) <=> (100, 100)");

        /* prints the string at the given position (100, 100) */
        outtextxy(100, 100, str);

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

  }





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


No comments:

Post a Comment