Thread: Darn enter key...

  1. #1
    Anonymous
    Guest

    Darn enter key...

    How can I make an input stream (e.g. getchar, fgets, scanf) do its thing or enter its input without having to push enter? like say i have a menu, with some options, eg (a)dd, (h)elp, i would like it to to add or go to help immediatly after pushing a or h, without having to push enter...do you understand? i hope...

    Im using gcc 2.9x on linux.

    PEACE

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    If you have Borlands conio.h, you can:
    Code:
    char Key = 0;
    while(Key != 'q')
    {
       Key = 0;
       if(kbhit()) Key = getch();
    
       if(Key == 'a')
       {
          ...
       }
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    gcc also has the same (or very similar, i dunno, check your man pages) conio kbhit() functionality
    hello, internet!

  4. #4
    Unregistered
    Guest
    If you read my post, I said I used linux, so how htne could i be using borland? thanks for your answer anyway... and I also do not want to use conio.h, itīs non stanfdard. any other solutions?

  5. #5
    Unregistered
    Guest
    great, google must be down or something...

    i dont have conio on my linux box, thatīs why im asking for an alternative, because surely there must be one...

    [highshool teacher quote]
    anyone? anyone?
    [/highschool teacher quote]

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>>and I also do not want to use conio.h, itīs non stanfdard. any other solutions?
    There is no standard C way to do what you ask.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Unregistered
    Guest
    oh, that sucks...

    can I use the conio.h that comes with libsdl and just throw it into
    /usr/include? will that work? if not, do you have any suggestions as to wherei can obtain a conio header?

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >i dont have conio on my linux box, thatīs why im asking for an alternative, because surely there must be one...
    You can fake it with Linux terminal commands, the simplest being:
    Code:
    .
    .
      system ( "stty raw" );
      ch = getchar();
      system ( "stty cooked" );
    .
    .
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to check memory left from malloc and free?
    By Lechx in forum C Programming
    Replies: 4
    Last Post: 04-24-2006, 05:45 AM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  3. Dialog Edit Control and Enter Key
    By Quantrizi in forum Windows Programming
    Replies: 2
    Last Post: 04-14-2004, 07:59 AM
  4. Need to capture the enter key
    By tyouk in forum Windows Programming
    Replies: 7
    Last Post: 11-08-2003, 06:07 PM
  5. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM