Thread: Dont want my program to wait for "enter"

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    13

    Dont want my program to wait for "enter"

    i made a simple password program. the password is a 4 digit number, you enter the password digit by digit and each time you enter one number it checks if it matches. if not you go back to the start. right now everytime you enter a number you need to press enter to have it checked, i would like for it to check everytime a number is entered instead of needing to press enter. im sure its something simple but this is my first c++ attempt :]

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    That's not possible in standard C++. The way C++ interacts with the console is to wait for the user to hit enter.

    To do what you want you have to use non-standard code that depends on your platform. The getch() function is available on several platforms and might help you do what you want to do.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    What OS are you using?

    The curses library (for *nix) provides several ways to do things like this - getch is available in several other platforms.

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    13
    windows xp

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Depending on your compiler, try getch(). You'll need to do look in your docs to find out what header file to include. The drawback here is that you'll have to handle backspace yourself - the system won't do it for you. If getch() is not available on your compiler, Google around (unless someone here already knows of a better solution. What you are wanting to do is called "uncooked" or "raw" input.

  6. #6
    Registered User
    Join Date
    Feb 2009
    Posts
    13
    heh, sounds like a pain in the ass so i wont bother :P. i have been using Borland 5.5

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Ahh... Borland. If you're doing a console app (command prompt - no windows) try conio.h

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Wait, every digit I enter is checked immediately and automatically?

    That's bad. That's really bad.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Consumer program
    By wise_ron in forum C Programming
    Replies: 11
    Last Post: 09-27-2006, 05:21 AM
  2. making my program sleep / wait / delay...
    By bobthebullet990 in forum C++ Programming
    Replies: 4
    Last Post: 08-13-2006, 10:14 AM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  4. How to make a program wait for an event?
    By DRoss in forum C++ Programming
    Replies: 0
    Last Post: 09-10-2001, 01:13 PM
  5. How can I make a program wait for an event?
    By DRoss in forum C++ Programming
    Replies: 0
    Last Post: 09-06-2001, 09:28 AM