Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Getch() for linux

  1. Aug 26, 2008 #1
    I use the linux operating system. And at present programming in C.
    The getch() doesn't seem to exist on Linux. I know that it is a DOS based command. What is the substitute for getch() on Linux.


    I mean is there any command out there which can take my input without displaying the output. I tried the getpass() command but it doesn't work fine

    Can someone please help.
     
  2. jcsd
  3. Aug 26, 2008 #2

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    getchar(), although if you need each character at a time without waiting for the enter key you might have to set the terminal mode.
    Remember unix is written in C and C was invented for unix so any good C book (such as K&R) will apply directly to unix/linux
     
  4. Aug 27, 2008 #3
    Can you please repeat the name of the book. I mean i don't know the acronym
     
  5. Aug 27, 2008 #4

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

  6. Aug 29, 2008 #5

    jim mcnamara

    User Avatar
    Science Advisor
    Gold Member

    I don't have my example at hand. You have to use termios to set the terminal (tty) to non-canonical mode, read a keystroke, then reset the tty to canonical mode.

    In other words it is OS dependent - the example I gave was unix-based. Windows has a call - _getche() as I remember. You can set the tty mode in windows as well.
     
  7. Aug 29, 2008 #6

    jim mcnamara

    User Avatar
    Science Advisor
    Gold Member

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Getch() for linux
  1. Fortran in Linux (Replies: 3)

  2. Learn linux (Replies: 6)

  3. Worth it to use linux? (Replies: 2)

Loading...