Thursday, March 17, 2011

gotoxy in code::block

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;
  }

19 comments:

  1. Very nice code... thank a lot....

    ReplyDelete
  2. Thank you!!!
    It worked!!

    ReplyDelete
  3. Exactly what i needed, thank you!!

    ReplyDelete
  4. Muchas gracias :D :D :D!!!

    ReplyDelete
  5. Just curious, for Linux and other systems that support escape sequences, do so.

    void gotoxy(int x,int y)
    {
    static const char *CSI = "\33["; // Esc (Escape) -> 27(10) = 33(8) = 1B(15)
    printf("%s%i;%iH", CSI, x, y);
    }

    ReplyDelete
  6. gracias hermano, queda entendido.

    ReplyDelete
  7. Thank u so much its workink.........

    ReplyDelete
  8. How to increase the font size in that?

    ReplyDelete
  9. It doesn't work for me the windows.h and stdlib.h to use gotoxy

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  10. This comment has been removed by the author.

    ReplyDelete