| Author |
Press any key to continue...
|
|
| John Smith 2004-10-28, 5:51 pm |
| Hello
What the easiest way to implement "Press any key to continue..." behavior in
the most portable way?
Under windows theres alot of ways like using system() to run the program
pause or using _getch().
What would the easiest way be under Linux?
Thanks in advance.
-- John
| |
| Måns Rullgård 2004-10-28, 5:51 pm |
| "John Smith" <john.smith@x-formation.com> writes:
> Hello
>
> What the easiest way to implement "Press any key to continue..." behavior in
> the most portable way?
>
> Under windows theres alot of ways like using system() to run the program
> pause or using _getch().
> What would the easiest way be under Linux?
getc();
This will require the user to press return, but Unix users expect that
anyway.
--
Måns Rullgård
mru@inprovide.com
| |
| Pascal Bourguignon 2004-10-28, 5:51 pm |
| "John Smith" <john.smith@x-formation.com> writes:
> What the easiest way to implement "Press any key to continue..." behavior in
> the most portable way?
Get some sticker and an indelible pen. Write the word "any" on the
non-sticky face of the sticker. Paste the sticker with the "any" word
up on some key of your keyboard. Provide the user with good spectacles.
--
__Pascal Bourguignon__ http://www.informatimago.com/
Voting Democrat or Republican is like choosing a cabin in the Titanic.
| |
|
| John Smith wrote:
> What the easiest way to implement "Press any key to continue..." behavior in
> the most portable way?
>
> Under windows theres alot of ways like using system() to run the program
> pause or using _getch().
> What would the easiest way be under Linux?
#include <stdio.h>
#include <termios.h>
void switch_buffering(int onoff)
{
static struct termios stored_settings;
struct termios new_settings;
if (!onoff) {
tcgetattr(0, &stored_settings);
new_settings = stored_settings;
new_settings.c_lflag &= (~ICANON);
new_settings.c_cc[VTIME] = 0;
new_settings.c_cc[VMIN] = 1;
tcsetattr(0, TCSANOW, &new_settings);
} else {
tcsetattr(0, TCSANOW, &stored_settings);
return;
}
}
int main()
{
/*
* Call function to switch off terminal line buffering, so a char
* from stdin will be delivered inmediately.
* Then we can now use getchar() to wait for any key.
*/
switch_buffering(0);
printf("Press any key to continue ");
getchar();
/* Restore original buffering settings. */
switch_buffering(1);
printf("\n");
printf("Continuing...\n");
return 0;
}
/* EOF */
Heiko
|
|
|
|