Any key...

This is a discussion on Any key... within the C Programming forums, part of the General Programming Boards category; How would you make it so when the user hits and key on the keyboard, he's brought to the main ...

  1. #1
    Unregistered
    Guest

    Any key...

    How would you make it so when the user hits and key on the keyboard, he's brought to the main function ( int main() )? Need it for a program I'm working on.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    There isn't any universally good way to do this, although it can be done, depending on the program.

    One way would be to make it so that every function call that takes you away from main, you call like...

    if (imAFunction () == -1) return -1;

    Also, for the point at which you want to escape to main by hitting a key,

    if (hitkey()) return -1;

    The hitkey function you'll have to replace by checking into your compilers documentation... especially take note to look for bios functions, or keyboard functions.
    Callou collei we'll code the way
    Of prime numbers and pings!

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    1
    How about reading the input from "any key" and then testing it with an 'if' statement. If it is '/n' for instance, return to main(), if not (ie 'else') return to main() aswell.

    Just a thought.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 05:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 05:42 PM

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