Pages

Saturday, 23 April 2016

Gotoxy

gotoxy(int x,int y) is very important function which help to move the cursor at our desire location of screen .gotoxy(int x,int y)  is built in function of  turbo c  but in gcc compiler it won't work.If you are using code::blocks IDE then you may get error with gotoxy. We have to add code for gotoxy in gcc or codeblocks. This code used windows.h header file in other word we can say its not the c code but it is the widows code. It won't work in linux machine because there is no windows.h library.



source code(or download)  for gotoxy is as follows:
#include<windows.h> //  header file for gotoxy
#include <stdio.h>     //header file for standard input output

COORD coord={0,0}; // this is global variable
                                    //center of axis is set to the top left cornor of the screen
void gotoxy(int x,int y){
      coord.X=x;
      coord.Y=y;
      SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
int main(){
      //calling these function
      gotoxy(20,20);printf("This is demo of gotoxy function");            
      return 0;
}

No comments:

Post a Comment