Exit

D

Danny

HI

How would i go about implimenting a bit of code that will exit the
program upon the pressing of any key, and also for that of a predefined key.

Dan
 
D

Danny

It doesn't appear to tell me how i can exit a program by entering a
specific key or any key
 
V

Victor Bazarov

Danny said:
It doesn't appear to tell me how i can exit a program by entering a
specific key or any key

No, it doesn't. But it should be apparent that since you cannot
enter "any key", there is no way to do anything, exiting included.

If you find a way to enter a key, use "exit" function to exit the
program. RTFM.
 
K

Kevin Goodsell

Danny said:
It doesn't appear to tell me how i can exit a program by entering a
specific key or any key

Please don't top-post. Re-read section 5 of the FAQ for posting guidelines.

Sometimes the answer to a question of the form "How can I do X" is "You
can't."

-Kevin
 
J

Jim Fischer

Danny said:
It doesn't appear to tell me how i can exit a program by entering a
specific key or any key

The C/C++ programming languages do not provide built in support for
keyboard / keypad devices of any kind. So there is no "standard C/C++"
answer to how one interacts with keyboard/keypad devices (e.g., how to
perform nonblocking input with a QWERTY keyboard made by company X,
whose model number is Y, and which is attached to a brand K computer
that is running operating system Z).

HOWEVER: Platform-specific tasks can performed by a C/C++ program *iff*
the C/C++ program uses platform-specific programming tools -- e.g.,
system services that the operating system's "application program
interface" (API) makes available to all programs (not just C/C++
programs); custom libraries that are designed specifically for the
OS/hardware environment you are using, etc. For example, the Win32
console API provides Windows apps (not just C/C++ apps) with a set of
keyboard, mouse, and display primitives that Windows programmers can use
in their Win32 console applications (e.g., to detect key presses; to
capture mouse events; to manipulate the console display, etc.). The
Win32 app simply calls the appropriate Win32 API function, and then the
Win32 API carries out the "request" on the program's behalf. (Note that
the Win32 API is part of the Windows OS itself.) In the Linux world,
C/C++ programmers can use the custom 'ncurses' library to perform
Linux-specific console I/O tasks.

Since these platform-specific solutions are not features of the C/C++
languages proper, there are no "standard C/C++" answers to how they are
used. (IOW, the people/companies who create these platform-specific
tools also specify how the tools must be used.) To learn more about
platform-specific programming solutions, visit the newsgroups and/or
mailing lists that are dedicated to programming issues for the
particular platform you are working with -- e.g., the Linux programming
newsgroups; the MacOS programming newsgroups; the Windows programming
newsgroups; the PalmOS programming newsgroups, etc. The folks in those
groups should be able to help you with platform-specific programming
tasks that do not have "standard C/C++" answers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,138
Messages
2,570,801
Members
47,348
Latest member
nethues

Latest Threads

Top