Moveto() Function

moveto() function is used to move the current position c.p to the specified coordinates (X,Y). This function is used to draw line when it uses with another function lineto() which we have already discussed in previous section.

Declaration

void moveto(int x, int y);
  • moveto() function contains two parameters. First parameter specifies X-coordinate.
  • Second parameter specifies the Y-coordinate.
  • For better understanding go through the program:

Program

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd = DETECT, gm,x,y;

char arr[100];

initgraph(&gd, &gm, " ");

x=getx();

y=gety();

sprintf(arr, "current position before using moveto() function is (%d,%d).",x,y);

outtextxy(100,200,arr);

moveto(50, 50);

x=getx();

y=gety();

sprintf(arr, "current position after using moveto() function is (%d,%d).",x,y);

outtextxy(100,240,arr);

getch();

closegraph();

}

First of all above program will find out the current position with the help of the getx() and gety() functions and print the message and after that it will change the current position to (50,50) using moveto() function and again print the message.

Output

c graphics