Thread: quick question about getchar()

  1. #1
    Registered User
    Join Date
    Feb 2002

    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();

    while( (menu_choice != 'q') && (menu_choice != EOF) && (menu_choice != 27) )

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

    My best code is written with the delete key.

  3. #3


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

  4. #4
    Registered User
    Join Date
    Aug 2001
    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, 03:54 PM
  2. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  3. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  4. simple getchar question
    By sweets in forum C Programming
    Replies: 2
    Last Post: 04-11-2002, 08:40 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM