quick question about getchar()

This is a discussion on quick question about getchar() within the C Programming forums, part of the General Programming Boards category; I am trying to exit a loop when the users presses 'q', Ctrl-C, or ESC. The 'q' and Ctrl-C work, ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    51

    quick question about getchar()

    I am trying to exit a loop when the users presses 'q', Ctrl-C, or ESC. The 'q' and Ctrl-C work, but I am having some problems with ESC. There is probably something stupid I am missing, but I can't find it. Does anyone know why this is not working?

    Thnx for any help.



    --------------------------------------------------
    menu_choice = getchar();
    getchar();

    while( (menu_choice != 'q') && (menu_choice != EOF) && (menu_choice != 27) )
    {
    etc,etc,etc.
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Whether getchar can read ESC or not is system dependent.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Unregistered
    Guest

    Wink

    In several compilers getchar and getc expect pressing enter after a character.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    esc is

    && (menu_choice != '\x1b') in hex;
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick question (adding characters)
    By Cactus in forum C Programming
    Replies: 2
    Last Post: 09-24-2005, 04:54 PM
  2. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 05:44 AM
  3. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 12:04 PM
  4. simple getchar question
    By sweets in forum C Programming
    Replies: 2
    Last Post: 04-11-2002, 09:40 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 06:46 PM

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