Press Any Key to Continue in C

Press Any Key to Continue

 Press Any Key to Continue

Author Message

 Press Any Key to Continue

    What has everyone found to be the best way to do a 'press any key to
continue' prompt?  Not printing the prompt, but accepting the key.
Currently, I am using:

char ch;

ch = getch();

    The compiler doesn't like this because I don't do anything with ch.
I am sure that there is a better way that people have figured out, and I
just need to know what it is.

Thu, 15 May 1997 16:22:26 GMT

 Press Any Key to Continue

: ch = getch();

just take out the ch= then.

ie.

getch();

on a single line.

i've never heard of a compiler complaining about that (or ch=getch()
anyway). ;)

Al
--
100 little bugs in the code,   | I check my email more often than my
100 little bugs,               | answering machine.
fix a bug, compile again,      | So if you wish to reach me, email at

Fri, 16 May 1997 17:58:59 GMT

 Press Any Key to Continue

: char ch;
: ch = getch();

btw, in dos, i usuly put:

if(getch()==0) getch();

this way if the user presses one of the F keys or arrow keys for exemple,
the if will take care of it by adding a second getch(); (remember? F keys
sends a 0 followed by an int.)

good luck.

Al
--
100 little bugs in the code,   | I check my email more often than my
100 little bugs,               | answering machine.
fix a bug, compile again,      | So if you wish to reach me, email at

Fri, 16 May 1997 18:01:51 GMT

 Press Any Key to Continue

Quote:

>    What has everyone found to be the best way to do a 'press any key to
>continue' prompt?  Not printing the prompt, but accepting the key.

I don't think there is a 'best' way, it is all based on your specific
requirements.

Quote:

>ch = getch();

>    The compiler doesn't like this because I don't do anything with ch.
>I am sure that there is a better way that people have figured out, and I
>just need to know what it is.

You can forget the 'ch =' part and just have 'getch();' and that will work.
Or depending on the compiler you might have a non-ANSI function that let's
you detect 'any' key being hit.  getch() won't tell you if the shift, alt,
cntl, etc keys are being hit.  The message "Press any key to continue" is
probably better served by saying "Press the Space Bar to continue", this
way you can even check to see if the proper key was hit.

MAR.

Fri, 16 May 1997 11:50:40 GMT

 Press Any Key to Continue

Quote:

>     What has everyone found to be the best way to do a 'press any key to
> continue' prompt?  Not printing the prompt, but accepting the key.
> Currently, I am using:

> char ch;

> ch = getch();

>     The compiler doesn't like this because I don't do anything with ch.
> I am sure that there is a better way that people have figured out, and I
> just need to know what it is.

You need to understand the difference between a compiler error and a
compiler warning. Your code will generate a warning, yet will still work
OK. If the warning bothers you, simply ignore the return value like this:

#include <stdio.h>
#include <conio.h>

main()
{
puts("Press any key to continue...");
getch();
return 0;

Quote:

}

-------------------------------------------------------------
MicroFirm: Down to the C in chips...
Home of SNIPPETS - Current release: SNIP9404.ZIP/LZH/ARJ/etc.
FidoNet 1:106/2000.6

Sat, 17 May 1997 00:48:42 GMT

 Press Any Key to Continue

Quote:

>     What has everyone found to be the best way to do a 'press any key to
> continue' prompt?  Not printing the prompt, but accepting the key.
> Currently, I am using:

> char ch;

> ch = getch();

>     The compiler doesn't like this because I don't do anything with ch.
> I am sure that there is a better way that people have figured out, and I
> just need to know what it is.

1) Are you saying that your compiler is complaining about un-optimized code ?
(smart compiler !)

2) You could f.ex. use:
getch();
to avoid the ch variable !

3) Now getch() is not standard but assuming your getch() acts like it
"usually" does, then you may have a problem with f.ex. function-keys
returning somekind of "start code" plus a "real code". You should then take
care to empty the buffer for the "real code" before continuing !

Joke: Where is the ANY key on my keyboard ?

                                                               Arne

Arne Vajh?j                             local DECNET:  KO::ARNE
Computer Department                     PSI:           PSI%238310013040::ARNE

                WWW URL: http://www.hhs.dk/~arne/arne.html

Sat, 17 May 1997 03:39:46 GMT

 Press Any Key to Continue

Last line of the program: print out ch, then clear screen.

        --Ken

=======================================================
#include <std/asimov.h>
1. A robot may not injure a human being or, through inaction, allow a
human being to come to harm.
2. A robot must obey orders given it by human beings except where such
orders would conflict with the First Law.
3. A robot must protect its own existence as long as such protection
does not conflict with the First or Second Law.

Sat, 17 May 1997 05:00:18 GMT

 Press Any Key to Continue

Quote:

>    What has everyone found to be the best way to do a 'press any key to
>continue' prompt?  Not printing the prompt, but accepting the key.

Related topic.  One of your repliers mentioned using "Press spacebar to continue"
I've found that specifying a key to press is helpful because the user might
press a key accidentally and not really be prepared to continue.  Sometimes the
'accident' is not paying attention.  The spacebar as a key is not the best choice.
It is too large and prone to being hit by mistake.  I find that the 'C' key (for
Continue) works well.

Tom Prodehl
Covia Technologies

Sat, 17 May 1997 04:21:26 GMT

 Press Any Key to Continue

Quote:

>     What has everyone found to be the best way to do a 'press any key to
> continue' prompt?  Not printing the prompt, but accepting the key.

    One way to do it is to make the message "Enter <a specific
sequence> to continue", use fgets(...,stdin) in a loop, and check
for EOF as well as the sequence you're expecting.

    I'm inclined to think that any case where you are justified in
stopping to say "Press any key to continue" could do with some
more rigorous check to prevent being zapped when a user stutters
on a key.

--

***             Count Templar, ELITE, Cobra Mk III (FM-287)             ***

Sat, 17 May 1997 07:05:32 GMT

 Press Any Key to Continue

Quote:

>    What has everyone found to be the best way to do a 'press any key to
>continue' prompt?  Not printing the prompt, but accepting the key.

I don't think there is a 'best' way, it is all based on your specific
requirements.

Quote:

>ch = getch();

>    The compiler doesn't like this because I don't do anything with ch.
>I am sure that there is a better way that people have figured out, and I
>just need to know what it is.

You can forget the 'ch =' part and just have 'getch();' and that will work.
Or depending on the compiler you might have a non-ANSI function that let's
you detect 'any' key being hit.  getch() won't tell you if the shift, alt,
cntl, etc keys are being hit.  The message "Press any key to continue" is
probably better served by saying "Press the Space Bar to continue", this
way you can even check to see if the proper key was hit.

MAR.

Fri, 16 May 1997 11:50:40 GMT

 Press Any Key to Continue

Quote:

>    What has everyone found to be the best way to do a 'press any key to
>continue' prompt?

First, you'll need an 'any' key on your keyboard.  They are pretty rare
these days; I don't remember seeing them on one of the AT - style
keyboards at all.  Can anybody enlighten us when they appeared, and
why they were dropped?

Since people could not agree on which key to use after the 'any' key was
no longer offered on keyboards, nowadays most programs accept quite a
number of keys in its place, but not all of them; for example, the
'shift', 'control', and 'alt' keys rarely work, whereas 'space'
and 'return' usually will.

Quote:

>Not printing the prompt, but accepting the key.
>Currently, I am using:
>char ch;
>ch = getch();

This may work for MS-DOS systems, but not, for example, for UNIX,
where there usually is no 'getch()' function.

Quote:

>    The compiler doesn't like this because I don't do anything with ch.

Hmm... you should use an int for ch.  Alternatively, you could just
write "(void) getch();" to get the compiler to shut up.
--

The joy of engineering is to find a straight line on a double
logarithmic diagram.

Sun, 18 May 1997 00:50:53 GMT

 Press Any Key to Continue

[}>
[}>Joke: Where is the ANY key on my keyboard ?
[}>

I work for an End User Support group. I've actually gotten a call with this
question. The user didn't quite finish the sentence, then hung up. I guess he
was having a bad day.


Amaze your friends! Stupefy your neighbors! Dazzle your detractors!
...........THINK!
These are MY opinions. AT&T Global Information Solutions can speak for itself.

Sun, 18 May 1997 05:30:42 GMT

 Press Any Key to Continue

: >ch = getch();

: This may work for MS-DOS systems, but not, for example, for UNIX,
: where there usually is no 'getch()' function.

Sorry but I don't have anything to do today, thus:

Thomas, I believe there's a getch function in UNIX (#include
curses)... :-)

And he if you don't want curses, then you may try getc(), which is the
same thing... :-)

Best regards,

Carlos...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I always say it: That of the Caribbean [sea] is a superior culture. I
shall not argue this with anybody, much less with people from inferior
cultures.
R. Hernandez.

Mon, 19 May 1997 05:42:46 GMT

 Press Any Key to Continue

:>    What has everyone found to be the best way to do a 'press any key to
:>continue' prompt?  Not printing the prompt, but accepting the key.
:I don't think there is a 'best' way, it is all based on your specific
:requirements.

here is A Portable Way:

    printf("Press <enter> to continue:\n");
fflush(stdout);
while (getchar() != '\n')
;

:>ch = getch();

:You can forget the 'ch =' part and just have 'getch();' and that will work.
: Or depending on the compiler you might have a non-ANSI function that let's
:you detect 'any' key being hit.

Um... which function in (ch = getch()) was standard-ANSI in the first place?
--

Mon, 19 May 1997 10:33:21 GMT

 Press Any Key to Continue

Quote:

>>    What has everyone found to be the best way to do a 'press any key to
>> continue' prompt?

Yeah, I use:

        Press A Key To Continue...

That way the clueless can press the "A" key, and the clueful can
press any key they like.

--
Chris Sonnack       | 3M/Information Technology/Engineering Info Svcs

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Rust Never Sleeps"

Mon, 19 May 1997 00:24:39 GMT
 [ 25 post ] Go to page: [1] [2]

provenzanoworlse.blogspot.com

Source: http://computer-programming-forum.com/47-c-language/07170dbe3e3d2825.htm

0 Response to "Press Any Key to Continue in C"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel