Thread: display a char at a particular co ordinates on screen

  1. #1
    Dragon Rider jas_atwal's Avatar
    Join Date
    Nov 2007
    Location
    India
    Posts
    54

    display a char at a particular co ordinates on screen

    I want to display a character at specific positions on screen using values like x and y. Is it possible?? i am not able to find the correct function. I tried to google but no luck.
    -------------------------------------------------------------------
    There are 10 kinds of people in this world....Those who understand binary and those who don't

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    You're looking for gotoxy().

  3. #3
    Dragon Rider jas_atwal's Avatar
    Join Date
    Nov 2007
    Location
    India
    Posts
    54
    Quote Originally Posted by Desolation View Post
    You're looking for gotoxy().
    Thank you. But I assume that is not a standart C function. It is included in conio.h in windows. Is there a smiliar implimentation for linux/unix systems as well?

    Maybe curses.h. I'll try that.
    -------------------------------------------------------------------
    There are 10 kinds of people in this world....Those who understand binary and those who don't

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    ncurses is more portable than conio.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    i have the same problem and ncurses(.h) is not found by c++
    Code:
    #include <iostream>
    #include <ncurses.h>
    using namespace std;
    
    int main() {
    	gotoxy(3, 5); // what's the right command if the include file would work??
    	cout << "blah" << endl;
    	cin.get();
    }

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Here. And don't forget to read the documentation. A good tutorial site can be found here.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    Quote Originally Posted by Devils Child View Post
    i have the same problem and ncurses(.h) is not found by C++
    ncurses is not standard header file. meaning, you have to link to it, which of course means you have to have it installed in your system first in order to work.

    if portability is not of concern, then by all means, go with windows.h and use gotoxy, otherwise, install ncurses or pdcurses in your system, usually for usage in windows this means copying a dll to c:\windows\system32 and finding the appropriate linker command (should be in the documentation of the library).

  8. #8
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    the windows.h include file does not support gotoxy(). thats what VS C++ said...
    portability - do you mean between operating systems? i mean - this IS portable to ALL other windows based computers when i use windows.h?

  9. #9
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    right portablility means between OS. including windows.h in a win32 app should work on any 2000/XP machine, and I would imagine it should work just fine with vista too (if it's a simple console app)

    right, I think gotoxy like you said is in conio.h, another non-standard header. i do know there is a similar function in windows.h, although the name of this function eludes me right now, it's something like SetCursorPosition() or something of the sort.

    Personally, I would find the windows.h function and use that if this program is for your benefit only.

  10. #10
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    you mean like this?
    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    int main() {
    	SetCursorPos(5, 10);
    	cout << "blah" << endl;
    	system("PAUSE");
    }
    this simply does not change the cursor position at all. it writes to position <1|1>.
    this does neither work without 'endl' or with printf!

  11. #11
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    Code:
    #include <windows.h>
    
    
    
    int main(){
    
        
    
        HANDLE console_handle;
    
        COORD cursor_coord;
    
        char *buffer = "X\n";
    
        DWORD actual = 0;
    
    
    
        cursor_coord.X=(40-(strlen(buffer)/2));
    
        cursor_coord.Y=10;
    
    
    
        console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
    
    
    
        if(SetConsoleCursorPosition(console_handle, cursor_coord)){
    
        
    
            WriteConsole(console_handle, buffer, strlen(buffer), &actual, NULL);
    
        }
    
        
    
        
    
        system("pause");
    
        return 0;
    
    }
    This is all I could find in my archives of old win32 console apps. I can't run this right now (have only Linux in front of me) but maybe this will work for you, maybe. Let me know how it goes...

  12. #12
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    that writes a questionmark to the screen. also it would propably be good if you could write whole words at once, wouldnt it?

  13. #13
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    I just went to my Desktop, compiled exactly what I posted, and it worked. To write an actual word, just replace "x\n" with "word\n". I'm not sure why it printed a "?" to your screen.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  2. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  3. Replies: 6
    Last Post: 06-30-2005, 08:03 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 11:57 AM