C How to Quit a Program C Press Any Key to Continue

press any key to continue

 press any key to continue

Author Message

 press any key to continue

Hi,

I would like to emulate at the end of a page, the line that you find on
the dos window at the end of a program 'press any key to continue'.
when I use getchar() I need also to press  on enter to continue.
How can I remedy to this?

Thanks

Philippe

Sun, 16 Feb 2003 03:00:00 GMT

 press any key to continue

: Hi,

: I would like to emulate at the end of a page, the line that you find on
: the dos window at the end of a program 'press any key to continue'.
: when I use getchar() I need also to press  on enter to continue.
: How can I remedy to this?

By using system-specific extensions. The C standard only specifies
buffered IO.

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #80 D+ ADA N+++ |
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/

"Remember: There are only three kinds of people - those who can count and those
who can't."
- Vampyra

Mon, 17 Feb 2003 03:00:00 GMT

 press any key to continue

Quote:

> Hi,

> I would like to emulate at the end of a page, the line that you find on
> the dos window at the end of a program 'press any key to continue'.
> when I use getchar() I need also to press  on enter to continue.
> How can I remedy to this?

Change your message to "press ENTER to continue", or use non-standard
extensions provided by your compiler.

--

Richard Heathfield

"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.

C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
65 K&R Answers: http://users.powernet.co.uk/eton/kandr2/index.html (32
to go)

Mon, 17 Feb 2003 03:00:00 GMT

 press any key to continue

Quote:

> Hi,

> I would like to emulate at the end of a page, the line that you find on
> the dos window at the end of a program 'press any key to continue'.
> when I use getchar() I need also to press  on enter to continue.
> How can I remedy to this?

> Thanks

> Philippe

Hello Philippe,

what you need is a unbuffered input. This can't be achived
in standard C you will have to use some system specific
extension (getch() on a DOS-Box or Unix-host with curses,
but be careful the two getch() functions from conio.h and
curses.h are definitly not the same).

A newsgroup related to your system can give you more help.

        Z

--
LISP is worth learning for the profound enlightenment experience you
will have when you finally get it; that experience will make you a
better programmer for the rest of your days.         Eric S. Raymond

Mon, 17 Feb 2003 03:00:00 GMT

 press any key to continue

This can only be done using system specific non-standard extensions. Under
windows check out the
kbhit() function, and under unix/linux try setting the terminal into
non-canocial mode.

Regards,
Paul

Quote:

> Hi,

> I would like to emulate at the end of a page, the line that you find on
> the dos window at the end of a program 'press any key to continue'.
> when I use getchar() I need also to press  on enter to continue.
> How can I remedy to this?

> Thanks

> Philippe

Mon, 17 Feb 2003 03:00:00 GMT

 press any key to continue

Quote:

>> I would like to emulate at the end of a page, the line that you find on
>> the dos window at the end of a program 'press any key to continue'.
>> when I use getchar() I need also to press  on enter to continue.
>> How can I remedy to this?

>Change your message to "press ENTER to continue", or use non-standard
>extensions provided by your compiler.

Heh.  First thought was of that episode of the Simpsons, where Homer's on AOL
or some such ISP...

--------
AndrewJ

 "Any key, where's the any key?" - Homer Simpson.

Mon, 17 Feb 2003 23:12:28 GMT

 press any key to continue

Quote:

> Thanks everyone for your help.

> two answers were very helpfull

> one answer was                system("PAUSE") ; // stdlib.h
> the other one was              getch() ;                 // conio.h

The more helpful answers you got, whether you realise it or not, were
the ones which pointed out that the best way to do what you want
portably is to change the message to read "Press ENTER to continue".
system() is portable, but PAUSE isn't. getch() is not portable. Of the
two bad solutions, you've picked the least bad, but you have not picked
the best available to you.

Quote:

> since I am using Vc, I will go with the first one.

I don't see the logic here.

--
Richard Heathfield
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
65 K&R Answers: http://users.powernet.co.uk/eton/kandr2/index.html (32
to go)

Sat, 22 Feb 2003 14:45:16 GMT

 press any key to continue

Quote:

> > Thanks everyone for your help.

> > two answers were very helpfull

> > one answer was                system("PAUSE") ; // stdlib.h
> > the other one was              getch() ;                 // conio.h

> The more helpful answers you got, whether you realise it or not, were
> the ones which pointed out that the best way to do what you want
> portably is to change the message to read "Press ENTER to continue".
> system() is portable, but PAUSE isn't. getch() is not portable. Of the
> two bad solutions, you've picked the least bad, but you have not picked
> the best available to you.

sure but the question was any key not enter...

Quote:

> > since I am using Vc, I will go with the first one.

> I don't see the logic here.

conio.h is not Vc compatible

Quote:

> --
> Richard Heathfield
> "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
> C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
> 65 K&R Answers: http://users.powernet.co.uk/eton/kandr2/index.html (32
> to go)

Sat, 22 Feb 2003 16:01:13 GMT

 press any key to continue

The grid bug bites!  Philippe Rousselot writes:

Quote:

>> > Thanks everyone for your help.

>> > two answers were very helpfull

>> > one answer was                system("PAUSE") ; // stdlib.h
>> > the other one was              getch() ;                 // conio.h

>> The more helpful answers you got, whether you realise it or not, were
>> the ones which pointed out that the best way to do what you want
>> portably is to change the message to read "Press ENTER to continue".
>> system() is portable, but PAUSE isn't. getch() is not portable. Of the
>> two bad solutions, you've picked the least bad, but you have not picked
>> the best available to you.

>sure but the question was any key not enter...

... which can't be done portably.  ENTER is a much better solution, in
my opinion.

Quote:

>> > since I am using Vc, I will go with the first one.

>> I don't see the logic here.

>conio.h is not Vc compatible

Perhaps, then, you should go with a solution that will work on all
compilers?  Using the functions in stdio.h should do the trick.

Sat, 22 Feb 2003 17:20:10 GMT

 press any key to continue

Quote:

> > > Thanks everyone for your help.

> > > two answers were very helpfull

> > > one answer was                system("PAUSE") ; // stdlib.h
> > > the other one was              getch() ;                 // conio.h

> > The more helpful answers you got, whether you realise it or not, were
> > the ones which pointed out that the best way to do what you want
> > portably is to change the message to read "Press ENTER to continue".
> > system() is portable, but PAUSE isn't. getch() is not portable. Of the
> > two bad solutions, you've picked the least bad, but you have not picked
> > the best available to you.

> sure but the question was any key not enter...

And the answer is that there is no portable solution.

When you ask in comp.lang.c, it is assumed that you are after a portable
solution. After all, if you wanted a system-specific solution, you'd
have asked in a system-specific newsgroup, right?

Quote:

> > > since I am using Vc, I will go with the first one.

> > I don't see the logic here.

> conio.h is not Vc compatible

And system("PAUSE") won't work on Unix systems. So you shouldn't use
that solution either. After all, you want to be portable, don't you?

--
Richard Heathfield
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
65 K&R Answers: http://users.powernet.co.uk/eton/kandr2/index.html (32
to go)

Sun, 23 Feb 2003 05:46:20 GMT

 press any key to continue

Quote:

> > The more helpful answers you got, whether you realise it or not, were
> > the ones which pointed out that the best way to do what you want
> > portably is to change the message to read "Press ENTER to continue".
> > system() is portable, but PAUSE isn't. getch() is not portable. Of the
> > two bad solutions, you've picked the least bad, but you have not picked
> > the best available to you.

> sure but the question was any key not enter...

Then you'll have to pay support people who explain to the customers
how to locate the `any' key on their keyboard, or why the RESET key is
not exactly `any' key.
--
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

Sun, 23 Feb 2003 02:32:21 GMT

mickligine.blogspot.com

Source: http://computer-programming-forum.com/47-c-language/457f59c4bac79998.htm

0 Response to "C How to Quit a Program C Press Any Key to Continue"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel