Thread: Press Enter to go back, press 0 to exit

  1. #1
    Registered User
    Join Date
    Jun 2014
    Posts
    3

    Press Enter to go back, press 0 to exit

    Hi. I'm new in C programming. I'm using C Dev Compiler. I went for a class in programming and I made 81 programs all in all. So I want to compile them in one program (you know, to enhance my programming skills). So when a user enters his choice and already in my, example, in my "7. Fruits Program", and if he wants to go back to the main menu, he presses Enter and when he wants to quit, he'll press 0. Any ideas?
    Last edited by Deanz Tinio; 06-06-2014 at 06:51 PM. Reason: grammar

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Standard C/C++ do not have an interface to query specific keyboard input.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  3. #3
    Registered User
    Join Date
    Jun 2014
    Posts
    3
    What!? You can't?

  4. #4
    Registered User
    Join Date
    Jun 2014
    Posts
    3
    is there another way?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You read a line using fgets().

    Then you examine the buffer to see if it contains zero, a number or just a blank \n.

    Then you do whatever you need to in each case.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Alternatively, you may use a library that does offer such an interface like "curses".

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 07-02-2011, 11:18 AM
  2. Press Enter Twice
    By Alone882 in forum C++ Programming
    Replies: 14
    Last Post: 01-04-2011, 01:45 PM
  3. press ESCAPE to exit
    By rafay_07 in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2010, 12:53 PM
  4. Exit on key press?
    By dazed in forum C Programming
    Replies: 3
    Last Post: 12-09-2002, 07:46 PM
  5. if i press enter
    By abbynormal87 in forum C++ Programming
    Replies: 5
    Last Post: 05-02-2002, 05:37 PM

Tags for this Thread