C Enter Any Key to Continue

"Press any key to continue"

 "Press any key to continue"

Author Message

 "Press any key to continue"

I have run out of idea
if its not too complicated, maybe someone write a code for "press any key to
continue"  and post it here?? anykey will include the wide space
(spacebar)...

printf ("Press any key to continue");
{ whats the code here??}

regards
vyn

Tue, 18 Dec 2001 03:00:00 GMT

 "Press any key to continue"

Quote:

>I have run out of idea
>if its not too complicated, maybe someone write a code for "press any key to
>continue"  and post it here?? anykey will include the wide space
>(spacebar)...

>printf ("Press any key to continue");
>  { whats the code here??}

Unfortunately, there is no *standard* function that is specifically defined to
get a key and return without a carriage return.  One of those "compatibility"
issues, I think.  Anyway, though it's not standard, see if your system lets you
use "conio.h."  I believe that there's a function in there that'll do what you
want.

Grant D. Watson

Tue, 18 Dec 2001 03:00:00 GMT

 "Press any key to continue"

Quote:

>if its not too complicated, maybe someone write a code for "press any key to
>continue"  and post it here?? anykey will include the wide space

There is no portable way to do this.  Please see the comp.lang.c FAQ,
section 19.1:

        19.1:   How can I read a single character from the keyboard without
waiting for the RETURN key?  How can I stop characters from
being echoed on the screen as they're typed?

That being said, there are probably many non-portable ways to do this
for your platform.  Ask in a newsgroup dedicated to your operating

--
Robert B. Clark
Visit ClarkWehyr Enterprises On-Line at http://www.iquest.net/~rclark/ClarkWehyr.html

Tue, 18 Dec 2001 03:00:00 GMT

 "Press any key to continue"

Hi,
My lecturer at college told me that you specify a variable in the function
heading, e.g. char key
Then in the main body of the function you do:

printf ("Press any key to continue");
gets(key);

You can specify specific keys that exit etc.
Hope this helps.

Quote:

> I have run out of idea
> if its not too complicated, maybe someone write a code for "press any key
to
> continue"  and post it here?? anykey will include the wide space
> (spacebar)...

> printf ("Press any key to continue");
>   { whats the code here??}

> regards
> vyn

Tue, 18 Dec 2001 03:00:00 GMT

 "Press any key to continue"

Quote:

>Hi,
>  My lecturer at college told me that you specify a variable in the function
>heading, e.g. char key
>Then in the main body of the function you do:

>printf ("Press any key to continue");
>gets(key);

1. NEVER use gets().
2. The OP was asking how to get a keypress and immediately resume
execution of his program; as others have stated, that's not possible in
standard C (except for special things like a newline or EOF).

Quote:

>You can specify specific keys that exit etc.
>Hope this helps.

It didn't. Please read the FAQ and this group's newsfeed for a few weeks
before posting.

Gergo

--
Our documentation manager was showing her two year old son around the
office.  He was introduced to me, at which time he pointed out that we
were both holding bags of popcorn.  We were both holding bottles of
juice.  But only *_ _ he* had a lollipop.

He asked his mother, "Why doesn't HE have a lollipop?"

Her reply:

        "He can have a lollipop any time he wants to.  That's what it
means to be a programmer."

GU d- s:+ a--- C++>$ UL+++ P>++ L+++ E>++ W+ N++ o? K- w--- !O !M !V
PS+ PE+ Y+ PGP+ t* 5+ X- R>+ tv++ b+>+++ DI+ D+ G>++ e* h! !r !y+

Tue, 18 Dec 2001 03:00:00 GMT

 "Press any key to continue"

Quote:

>  My lecturer at college told me that you specify a variable in the function
>heading, e.g. char key
>Then in the main body of the function you do:

>printf ("Press any key to continue");
>gets(key);

Ah, but you need to terminate the string with a newline.  This does not
satisfy the "press any key to continue" requirement.

--
Robert B. Clark
Visit ClarkWehyr Enterprises On-Line at http://www.iquest.net/~rclark/ClarkWehyr.html

Tue, 18 Dec 2001 03:00:00 GMT

 "Press any key to continue"

[...]
: My lecturer at college told me that you specify a variable in the
: function heading, e.g. char key
: Then in the main body of the function you do:

: printf ("Press any key to continue");
: gets(key);

Either you understood your lecturer incorrectly, or your lecturer
is giving you very bad information.

First of all, gets() requires a char * as parameter, not char.
Your example won't even compile.  Secondly, you should refer to
the FAQ:

12.23:  Why does everyone say not to use gets()?

Tue, 18 Dec 2001 03:00:00 GMT

 "Press any key to continue"

The closes I could get is to use 2 identical lines of getchar() like this...
printf("Press 'ENTER' to continue");
ch=getchar();
ch=getchar();

which will accept return key and other character keys... but I know this is
not the correct way.. in certain situation, the enter keys even have to be
press 2 times... or even 3 times...
Maybe someone could help correct my code??

regards,
vyn

Quote:

>I have run out of idea
>if its not too complicated, maybe someone write a code for "press any key
to
>continue"  and post it here?? anykey will include the wide space
>(spacebar)...

>printf ("Press any key to continue");
>  { whats the code here??}

>regards
>vyn

Wed, 19 Dec 2001 03:00:00 GMT

 "Press any key to continue"

Quote:

>The closes I could get is to use 2 identical lines of getchar() like this...
>    printf("Press 'ENTER' to continue");
>    ch=getchar();
>    ch=getchar();

>which will accept return key and other character keys... but I know this is
>not the correct way.. in certain situation, the enter keys even have to be
>press 2 times... or even 3 times...
>Maybe someone could help correct my code??

Use fgets().

Gergo

--
If I had a plantation in Georgia and a home in Hell, I'd sell the
plantation and go home.
-- Eugene P. Gallagher

GU d- s:+ a--- C++>$ UL+++ P>++ L+++ E>++ W+ N++ o? K- w--- !O !M !V
PS+ PE+ Y+ PGP+ t* 5+ X- R>+ tv++ b+>+++ DI+ D+ G>++ e* h! !r !y+

Wed, 19 Dec 2001 03:00:00 GMT

 "Press any key to continue"

There is no portable way to do that, so the answer is platform specific.
However, under MSDOS a lot of compilers support a function called getch()
which does exactly that! getch() function may be present in conio.h. So do
something like this:

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

main()
{
char ch;
/* do something */
printf("Press a key to continue....");
ch = getch();    /* ch stores the charachter code for the key pressed */
/* do some more stuff */

Quote:

}

Also check out a funtion called clrscr() in conio.h for clearing the screen!

Quote:

> >I have run out of idea
> >if its not too complicated, maybe someone write a code for "press any key
to
> >continue"  and post it here?? anykey will include the wide space
> >(spacebar)...

> >printf ("Press any key to continue");
> >  { whats the code here??}

Wed, 19 Dec 2001 03:00:00 GMT

 "Press any key to continue"

Quote:

>The closes I could get is to use 2 identical lines of getchar() like this...
>    printf("Press 'ENTER' to continue");
>    ch=getchar();
>    ch=getchar();

>which will accept return key and other character keys... but I know this is
>not the correct way.. in certain situation, the enter keys even have to be
>press 2 times... or even 3 times...
>Maybe someone could help correct my code??

To wait for a RETURN/ENTER (or equivalent) key to be pressed try this:

     int ch;
...

     while ((ch = getchar()) != EOF && ch != '\n')
;

--
-----------------------------------------

-----------------------------------------

Wed, 19 Dec 2001 03:00:00 GMT

barrettmationsills.blogspot.com

Source: http://computer-programming-forum.com/47-c-language/1303a5269e5ccab4.htm

0 Response to "C Enter Any Key to Continue"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel