How to use getch in Linux?

This is a discussion on How to use getch in Linux? within the C Programming forums, part of the General Programming Boards category; getch is in the conio.h i know, works perfectly well on windows, but on linux no no, iv seen others ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    46

    Question How to use getch in Linux?

    getch is in the conio.h i know, works perfectly well on windows, but on linux no no, iv seen others do functions for this in order to work in linux. How do u do this is my question, i just wnt to make it work on linux

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Write it yourself. getch() is not part of any of the C standards therefore no compiler has to include it. When it doubt google how to do such a thing. Or just use ncurses or something.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,764
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    scroll to the end.

    Or if you want fancy terminal "graphics", then look at ncurses library, which also has a key input function which works in a similar manner.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Wow... I never noticed that. Though its been many moons since I last read the FAQ, thanks Salem.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by Salem View Post
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    scroll to the end.

    Or if you want fancy terminal "graphics", then look at ncurses library, which also has a key input function which works in a similar manner.

    I tried the one to the end but didnt work

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by master5001 View Post
    Write it yourself. getch() is not part of any of the C standards therefore no compiler has to include it. When it doubt google how to do such a thing. Or just use ncurses or something.
    thanks again for answering matt

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by blondie.365 View Post
    I tried the one to the end but didnt work
    In what way did it not work? It looks about right to me.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wireless Network Linux & C Testbed
    By james457 in forum Networking/Device Communication
    Replies: 3
    Last Post: 06-11-2009, 12:03 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  3. Pls repair my basketball program
    By death_messiah12 in forum C++ Programming
    Replies: 10
    Last Post: 12-11-2006, 05:15 AM
  4. getch() equilvalent in Linux
    By Nakeerb in forum C++ Programming
    Replies: 8
    Last Post: 11-01-2002, 08:32 AM

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