the gotoxy

about gotoxy

Page 1 of 1

5 Replies - 4555 Views - Last Post: 07 February 2010 - 10:15 AM Rate Topic: -----

#1 nowee_021  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 05-February 10

the gotoxy

Posted 05 February 2010 - 07:12 AM

what is the library for the syntax gotoxy in c free?
Is This A Good Question/Topic? 0
  • +

Replies To: the gotoxy

#2 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: the gotoxy

Posted 05 February 2010 - 07:14 AM

I think it's defined in <conio.h>
Was This Post Helpful? 0
  • +
  • -

#3 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: the gotoxy

Posted 05 February 2010 - 07:27 AM

I guess that would depend upon the compiler you are using with C-Free.

Generally the syntax is gotoxy(int x, int y)

however, most compilers do not have conio.h -- and of the ones that do, most of them do not have the gotoxy -- I think for gotoxy you need borland's compiler.

You can however write your own. If you are on windows you can use:
//This will set the position of the cursor
void gotoXY(int x, int y)
{
     //Initialize the coordinates
     COORD coord = {x, y};
     //Set the position
     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
     return;
}


taken from my snippet.

to use the example above you need to include the 'windows.h' header file.

This post has been edited by NickDMax: 05 February 2010 - 07:30 AM
Reason for edit:: remembered about windows.h

Was This Post Helpful? 0
  • +
  • -

#4 nowee_021  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 05-February 10

Re: the gotoxy

Posted 05 February 2010 - 07:28 AM

it doesn't work with c free.
i tried different libraries but i was failed to find it out.
Was This Post Helpful? 0
  • +
  • -

#5 sweet.k.angel  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 33
  • Joined: 18-January 10

Re: the gotoxy

Posted 07 February 2010 - 05:51 AM

which compiler are you using???
Was This Post Helpful? 0
  • +
  • -

#6 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: the gotoxy

Posted 07 February 2010 - 10:15 AM

If you are on a windows platform and using a C++ compiler the following should compile:

gotoBath.cpp
#include <windows.h>
#include <iostream>

void gotoXY(int x, int y);
void ClearConsole();

using namespace std;

int main() {
    ClearConsole();
    gotoXY(0,0);
    cout << "I had a tiny turtle";
    gotoXY(5,1);
    cout << "his name was Tiny Tim";
    gotoXY(3,2);
    cout << "I put him in the bathtub";
    gotoXY(10,4);
    cout << "To see if he could swim.";
    gotoXY(0, 10);
    return 0;

}


//This will set the position of the cursor
void gotoXY(int x, int y)
{
     //Initialize the coordinates
     COORD coord = {x, y};
     //Set the position
     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
     return;
}

//This will clear the console.
void ClearConsole()
{
     //Get the handle to the current output buffer...
     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
     //This is used to reset the carat/cursor to the top left.
     COORD coord = {0, 0};
     //A return value... indicating how many chars were written
     //   not used but we need to capture this since it will be
     //   written anyway (passing NULL causes an access violation).
     DWORD count;
     //This is a structure containing all of the console info
     // it is used here to find the size of the console.
     CONSOLE_SCREEN_BUFFER_INFO csbi;
     //Here we will set the current color
     if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
     {
          //This fills the buffer with a given character (in this case 32=space).
          FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
          FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count );
          //This will set our cursor position for the next print statement.
          SetConsoleCursorPosition(hStdOut, coord);
     }
     return;
}


If it does not, you need to check the setup of C-Free since it would seem that you do not have it configured correctly.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1