Using gotoxy

This is a discussion on Using gotoxy within the C++ Programming forums, part of the General Programming Boards category; Alright, ive looked at the FAQ, and ive posted before, but i never get a good answer. this is my ...

  1. #1
    His posts are far and few Esparno's Avatar
    Join Date
    Mar 2002
    Posts
    100

    Using gotoxy

    Alright, ive looked at the FAQ, and ive posted before, but i never get a good answer. this is my last asking in the "quest for the holy gotoxy", can someone show me the code to output to the console window a "*" that moves from left to right? With comments please. im sorry for asking someone to do the code for me but i cant figure out the code even when i try dissecting it. sorry and thanks in advance
    Signature is optional, I didnt opt for one.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    #include <windows.h>
    #include <cstdio>
    #include <ctime>
    
    void sleep ( long m )
    {
      clock_t limit, cl = clock();
      limit = cl + m;
      while ( limit > cl )
        cl = clock();
    }
    
    void gotoxy ( int x, int y )
    {
       COORD coord;
       coord.X = (short)x;
       coord.Y = (short)y;
       SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), coord);
    }
    
    int main ( void )
    {
      char *c = "Code Goddess";
      int i, j;
      // Specify a limit for how long the program runs
      for ( i = 0; i < 5; i++ )
        // Specify the horizontal length for the marquee
        for ( j = 0; j < 60; j++ ) {
          /* Use gotoxy to set the x coordinate.
          ** A custom sleep function is used to slow
          ** the program down and then another call
          ** to gotoxy and printf to clear the previous
          ** print.
          */
          gotoxy ( j, 0 ), printf ( "%s", c );
          sleep ( 100 );
          gotoxy ( j, 0 ), printf ( "%*c", strlen ( c ), ' ' );
        }
      printf ( "\n" );
      return 0;
    }
    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User got matt?'s Avatar
    Join Date
    Mar 2002
    Posts
    16
    lol..thanks this kind of gives a new prespective on my racing game. By the way, Prelude you impress me by being everywhere at once. Also.. Is sunlight gonna never return?
    "If there is a will, there is a way."

  4. #4
    His posts are far and few Esparno's Avatar
    Join Date
    Mar 2002
    Posts
    100
    Thx , i cant talk in detail because my teacher is right here.
    Signature is optional, I didnt opt for one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is gotoxy??
    By Beachblue in forum C Programming
    Replies: 6
    Last Post: 11-23-2008, 01:24 AM
  2. Tic Tac Toe movement
    By $l4xklynx in forum Game Programming
    Replies: 4
    Last Post: 11-06-2008, 07:22 PM
  3. gotoxy(); help!!
    By clique in forum C Programming
    Replies: 2
    Last Post: 10-07-2008, 05:08 AM
  4. Want to see if I am using gotoxy the right way ...
    By o0obruceleeo0o in forum C++ Programming
    Replies: 5
    Last Post: 04-22-2003, 05:17 PM
  5. Is gotoxy ansi?
    By MeneLaus in forum C Programming
    Replies: 2
    Last Post: 05-18-2002, 03:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21