Is there something like a locate command?

This is a discussion on Is there something like a locate command? within the C++ Programming forums, part of the General Programming Boards category; I'm trying to find a way to cout "hi" in the same area of the screen repeadidly.... like i want ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    16

    Is there something like a locate command?

    I'm trying to find a way to cout "hi" in the same area of the screen repeadidly....
    like i want "Hi" to cout in the same coordinates of the screen each time... with it moving down the window....

    so in the top corner... x,y=1,1
    i want it to cout<< "hi"; in a loop....

    if you have no idea what i'm talking about i proabably explained it crappily.... but thatnks alot if you can help..

  2. #2
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Which compiler are you using?
    You can use gotoxy() which is included in conio.h or conio.c for Dev C++.

    Just do it this way:

    gotoxy(x,y);
    cout << "Hi!";
    gotoxy(x,y);
    cout << "Hi!";
    gotoxy(x,y);
    cout << "Hi!";
    etc..

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    16

    Thanks but..

    I'm getting this error....


    error C2065: 'gotoxy' : undeclared identifier

    maybe i'm just an idiot... or i'm missing something can you help???
    Thanks


    oh by the way i'm useing Microsoft Visual C++
    Last edited by CARBUNCLE; 04-23-2002 at 08:41 PM.

  4. #4
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    did you add this:

    #include <conio.h>

    Just below your #include <iostream> line?

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    16
    ya i did

  6. #6
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    Hmm. Well I'm not familiar with msvc but I am pretty sure it has gotoxy. How are you calling it from your program?

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    16
    Here i'll show ya what i got


    #include <iostream.h>
    #include <conio.h>

    int main()
    {

    int x=1,y=1;

    gotoxy(x,y);

    cout << "Hi!";
    gotoxy(x,y);
    cout << "Hi!";
    gotoxy(x,y);
    cout << "Hi!";

    return 0;
    }

  8. #8
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    Well, you aren't flushing cout like you ought to, but that isn't a compile-time problem.

    Maybe check your implementation's conio.h, see if they do something strange with gotoxy().

    Also, with MSVC, what is your target? Some types of non-console executables might not support gotoxy().

  9. #9
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    MSVC has no gotoxy() function

    heres and implementation of it from the FAQ.

    http://www.cprogramming.com/boardfaq.html#various
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    16
    This is my code now... it moves down diagnally like its supposed to but it.. it just dumps all the information at the end and i don't know why...

    if anyone can help me with this it would be greatly appreciated.

    #include <windows.h>
    #include <conio.h>
    #include<iostream.h>

    void gotoxy(int , int);

    int main()
    {

    for(int i=0;i<=100;i++)
    {
    gotoxy(i,i);
    cout << "hi";
    Sleep(40);
    }

    return 0;
    }

    void gotoxy(int x, int y)
    {
    COORD coord;
    coord.X = x;
    coord.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_H ANDLE), coord);

    }
    Last edited by CARBUNCLE; 04-24-2002 at 06:31 AM.

  11. #11
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Because you dont have 100 lines nor do you have 100 columns. I think its something like 80 cols and 25 rows for a normal console window

  12. #12
    Registered User
    Join Date
    Apr 2002
    Posts
    16
    OH! ok i know how now... THANK YOU SO MUCH for your help everyone!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. problem with "touch" command in c program
    By Moony in forum C Programming
    Replies: 10
    Last Post: 08-01-2006, 09:56 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. exe files in -c- language
    By enjoy in forum C Programming
    Replies: 6
    Last Post: 05-18-2004, 04:36 PM
  5. Replies: 3
    Last Post: 10-08-2001, 12:21 AM

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