## 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}; //initializationvoid 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.

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

1. same here , undefined reference to `SetConsoleCursorPostion'

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