Thread: faq: cached input with mygetch()

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    faq: cached input with mygetch()

    So I'm trying to put together a little text game at school on their redhat machines, right? I'm using a char buffer with system("clear") to write to the screen and mygetch() from the faq to get input.
    Code:
    int mygetch() {
      struct termios oldt,
                     newt;
      int            ch;
      tcgetattr( STDIN_FILENO, &oldt );
      newt = oldt;
      newt.c_lflag &= ~( ICANON | ECHO );
      tcsetattr( STDIN_FILENO, TCSANOW, &newt );
      ch = getchar();
      tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
      return ch;
    }
    This function does what I need, except it waits for keyboard input before returning a value. Is there any way to get it to return like 0 or something when there's no input, or maybe a whole other function that does that?
    Last edited by ichijoji; 04-07-2004 at 12:19 PM.
    Illusion and reality become impartiality and confidence.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input class project (again)
    By Elysia in forum C++ Programming
    Replies: 41
    Last Post: 02-13-2009, 10:52 AM
  2. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  3. Determining if input is int, double, or char
    By Lucid003 in forum C++ Programming
    Replies: 4
    Last Post: 11-16-2005, 04:16 PM
  4. EOF messing up my input stream?
    By Decrypt in forum C++ Programming
    Replies: 4
    Last Post: 09-30-2005, 03:00 PM
  5. FAQ Keyboard Input ? (C++)
    By Malikive in forum FAQ Board
    Replies: 6
    Last Post: 11-07-2001, 09:30 PM