gotoxy in Code::Blocks

Solution to gotoxy in codeblocks.

1. #include <windows.h>
2. Define a global variable  COORD coord = {0, 0}; // sets coordinates to 0,0
3. Make a function gotoxy()

void gotoxy (int x, int y) 
{  
        coord.X = x; coord.Y = y; // X and Y coordinates 
        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); 
}

You can call this gotoxy()  function to put cursor at any postion.

to change cursor type i.e. blinking,

_setcursortype(_NORMALCURSOR);  //for normal blinking cursor                               
_setcursortype(_NOCURSOR);  //for NO cursor

put these functions accordingly where u need it

SHARE gotoxy in Code::Blocks

You may also like...

9 Responses

  1. leila says:

    thanks for help.i do this but it wasn’t useful..
    #include
    #include
    using namespace std;
    int main()
    {
    gotoxy(12,5);
    cout<<“hello”;
    }
    error!:
    |6|error: ‘gotoxy’ was not declared in this scope|
    ||=== Build finished: 1 errors, 0 warnings ===|

  2. Reuter says:

    You’re a genious, thank you.

    Muchas gracias bato loco, me ha servido un montón.

    Paz

  3. @leila
    the function definition for the gotoxy must be placed before main function otherwise it must be declared and defined at any place you want. hope u can get away with that error.

  4. Andreas says:

    Hi this was very helpful! Thanks a lot !

  5. Anonymous says:

    hello,

    this was very very helpful… thnks a lot

  6. Thank you. Timely help.

  7. Anonymous says:

    hi just tried this one and it had an error. help please?

    here’s my code.

    #include
    #include
    #define coord = {0, 0};

    void gotoxy(int x, int y){
    coord.X= x;
    coord.Y= y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    }

    int main()
    {
    gotoxy(12,10);
    printf(“Hello world!n”);
    return 0;
    }

    error:expected expression before ‘=’ token

    • Instead of #define coord = {0,0}; put the following global variable
      COORD coord = {0, 0};

      Since the COORD is a structure which contains the structure for holding x and y coordinates.
      This may solve the problem.

Leave a Reply

Your email address will not be published. Required fields are marked *

Share