Thread: how can i make a gotoxy() function in c

  1. #1
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497

    how can i make a gotoxy() function in c

    hey guys, i am in need of such a function , i know there is one in windows.h (coord stuff) but i jjust want to give it a try myself first , and i intend to make that function portable ( meaning to be run on both win and nix systems ) .
    how should i go about it ?
    and by the way do we have sth like this ( portable ) rather than windows coord in c or c++ out there too?
    tanx in advance
    Last edited by Masterx; 06-10-2009 at 06:54 AM.
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Modern systems won't let you directly fiddle with the stuff you would need to do a gotoxy() without going through them. That means you must, directly or indirectly, play nice with the system and do it the way that it wants. You can't do raw writes to memory in a DOS type fashion.

    If you want to make this portable, you should write a Windows implementation and a *nix implementation. If you want to support any other systems, write implementations for those, too. What you could try to do is have your library detect the system in question and try to compile the proper implementation.

  3. #3
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497
    wow, tanx for the info, i didnt know thats that much difficult!
    anyways it seems i gotta use the windows solution for now :d
    thanx alot again
    by the way if weput those stuff aside , how should i got about it ? suppose i wnat to make one for windows! ( and without any help from windows.h ! i want to write it from scratch myself , what should i know and what else is necessary to be familiar with to be able to code such stuff?)
    Last edited by Masterx; 06-10-2009 at 06:53 AM.
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by Masterx View Post
    by the way if weput those stuff aside , how should i got about it ? suppose i wnat to make one for windows! ( and without any help from windows.h ! i want to write it from scratch myself , what should i know and what else is necessary to be familiar with to be able to code such stuff?)
    Let me try to rephrase it in a hopefully easier way to understand: You can't!

    Windows.h isn't there just to help you. It's there because Windows won't let you do a thing without its permission, and it's giving you a way to talk to it and ask it nicely to do something.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by MacGyver View Post
    Let me try to rephrase it in a hopefully easier way to understand: You can't!
    You're just being *way* too subtle here, MacGyver.

  6. #6
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497
    Quote Originally Posted by MacGyver View Post
    Let me try to rephrase it in a hopefully easier way to understand: You can't!

    Windows.h isn't there just to help you. It's there because Windows won't let you do a thing without its permission, and it's giving you a way to talk to it and ask it nicely to do something.
    thank you very very much for clarification :d but this is the first time in my whole life that sb tells me i cant do sth! i remember when i was asking some question back in 2007 in code guru, Paul McKenzie ( if i remember correctly ) told me that anything is possible but youve got to find its way of doing it right .
    i suppose you said that because im a beginner and thus incapable of coding such a thing, that might be true , but i do really wana know how they do it , just theoretically , im just curious now , and i appreciate any kind of info ( links , stuff) about this function .
    (forget about coding bro :d i know you know mylimits but lets do it)
    again i thank you .
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  7. #7
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Check out Console Functions (Windows)

    Specifically
    SetConsoleCursorPosition Function (Windows)

    For a windows solution.
    Curses probably for the *nix solution.

  8. #8
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by Masterx View Post
    thank you very very much for clarification :d but this is the first time in my whole life that sb tells me i cant do sth! i remember when i was asking some question back in 2007 in code guru, Paul McKenzie ( if i remember correctly ) told me that anything is possible but youve got to find its way of doing it right .
    I told you how to do it right. Do it the OS-specific way. valaris was kind enough to point out some Windows functions.

    Quote Originally Posted by Masterx View Post
    i suppose you said that because im a beginner and thus incapable of coding such a thing, that might be true , but i do really wana know how they do it , just theoretically , im just curious now , and i appreciate any kind of info ( links , stuff) about this function .
    No, I said it because it's the truth. The proper way of messing with a console is to use the system specific methods.

    Since you want to know theory.... OK, here you go. Make sure you follow these steps in the following order:

    1. Write your own OS.
    2. Write your own console.
    3. Implement your own OS-specific way of doing it.


    Quote Originally Posted by Masterx View Post
    (forget about coding bro :d i know you know mylimits but lets do it)
    again i thank you .
    What I keep telling you is that Windows won't let you mess around with raw memory. You have to do it via the Windows way. I'm starting to think you have a reading comprehension problem.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Shock and awe, it's been asked before!
    Cprogramming.com FAQ > gotoxy() in a Windows Console
    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.

  10. #10
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497
    Quote Originally Posted by MacGyver View Post
    I told you how to do it right. Do it the OS-specific way. valaris was kind enough to point out some Windows functions.



    No, I said it because it's the truth. The proper way of messing with a console is to use the system specific methods.

    Since you want to know theory.... OK, here you go. Make sure you follow these steps in the following order:

    1. Write your own OS.
    2. Write your own console.
    3. Implement your own OS-specific way of doing it.




    What I keep telling you is that Windows won't let you mess around with raw memory. You have to do it via the Windows way. I'm starting to think you have a reading comprehension problem.
    tanx, now i get it , i misunderstood you . tanx for the extra explanation .
    Quote Originally Posted by Salem View Post
    Shock and awe, it's been asked before!
    Cprogramming.com FAQ > gotoxy() in a Windows Console
    sorry bout that , but i knew this windows specific solution , i thought its not that hard and i anted to make one myself and the dear Mcgyver cleared the matter . anyways tanx for everything .
    Last edited by Masterx; 06-10-2009 at 10:02 AM.
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  3. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM