Saturday, August 27, 2011

gotoxy() function in Code::blocks(gcc compiler) using C

In Turbo C/C++ and Borland C++ compiler, gotoxy() is build in function. You need not have to write its function definition. All you have to do is call the function with arguments as x and y coordinate. But in modern C compiler like gcc and IDE Code::Blocks, gotoxy() is not  build-in function, you have to define it before use them. The following code is the function definition for gotoxy(). Remember: This function only works on windows, because the function definition includes functions of header file “windows.h”. So to use gotoxy() you must include “windows.h”.

COORD coordinate = {0,0}; //initialization
void gotoxy(int x, int y){ //function definition
   coordinate.X = x; coordinate.Y =  y;
   SetConsoleCursorPostion(GetStdHandle(STD_OUTPUT_HANDLE),coordinate);
}

NOTE: coordinate (0,0) is left-top corner of your window.

7 comments:

  1. but it is giving an error that "setconsolecursorposition" is undeclared. first use this function.

    ReplyDelete
    Replies
    1. same here , undefined reference to `SetConsoleCursorPostion'

      Delete
  2. Hi Adil, The error comes from here:

    SetConsoleCursorPostion(GetStdHandle(STD_OUTPUT_HANDLE),coordinate);

    We must change Postion by Position.

    SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);

    Regards

    ReplyDelete
  3. It gives an error that "expected ';' before 'COORD' "... Please help...

    ReplyDelete
  4. I have problem in this... This shows a error as... "expected ';' before 'COORD' "... Please Help

    ReplyDelete
  5. It gives an error that "expected ';' before 'COORD' "... Please help...

    ReplyDelete
  6. how to do make a linklist about the dequeue, dequeue,enqueue
    please help me...

    ReplyDelete