I need a PRESS_ANY_KEY_TO_CONTINUE function 
Author Message
 I need a PRESS_ANY_KEY_TO_CONTINUE function

I have tried:

void press_any_key (void)
{
        printf("Press any key to continue....");
        getchar();
        printf("\n");

Quote:
}

and I get a CODE HAS NO EFFECT warning from my IDE.

Also, it keeps getting characters until RETURN is pressed.  I want a
press *ANY* key function.  I have #include <stdio.h>   already executed also.
So please give me a little help.  Thanks.

Eric Buschelmann



Sat, 10 Jan 1998 03:00:00 GMT  
 I need a PRESS_ANY_KEY_TO_CONTINUE function

Quote:

>Also, it keeps getting characters until RETURN is pressed.  I want a
>press *ANY* key function.

That is what getchar() does.  What your asking for is a platform
specific function.  I deduce from the use of the term IDE, that you
are using DOS.  If this is true, look for getch().

Bruce



Sun, 11 Jan 1998 03:00:00 GMT  
 I need a PRESS_ANY_KEY_TO_CONTINUE function

Quote:

>I have tried:

>void press_any_key (void)
>{
>    printf("Press any key to continue....");
>    getchar();
>    printf("\n");
>}
>and I get a CODE HAS NO EFFECT warning from my IDE.

>Also, it keeps getting characters until RETURN is pressed.  I want a
>press *ANY* key function.  I have #include <stdio.h>   already executed also.
>So please give me a little help.  Thanks.

>Eric Buschelmann


Eric, try this:

#include <sys/termios.h>

...

struct termios t;

...

void press_any_key (void)
{
       disable_echo();
       printf("Press any key to continue....");
       getchar();
       printf("\n");
       enable_echo();

Quote:
}

disable_echo()
{
   i=ioctl(0, TCGETS, &t);
   t.c_cc[VEOF]=1;
   t.c_iflag|=IGNCR;
   t.c_lflag&=(~ISIG);
   t.c_lflag&=(~ICANON);
   t.c_lflag&=(~ECHO);
   i=ioctl(0, TCSETS, &t);

Quote:
}

enable_echo()
{
   i=ioctl(0, TCGETS, &t);
   t.c_cc[VEOF]=4;
   t.c_iflag&=(~IGNCR);
   t.c_lflag|=ISIG;
   t.c_lflag|=ICANON;
   t.c_lflag|=ECHO;
   i=ioctl(0, TCSETS, &t);

Quote:
}

If you leave echo disabled when you exit your program, you'll have
a good time trying to enter your next command.

Typically, you get a "code has no effect" warning when you have
executable statements following a "return" or "exit" statement in a
block of code, or following an "if" or "while" statement with an
argument that evaluates to zero at compile time (ie, a constant
expression).

Good luck.
Warren Ring
AB6QE



Sun, 11 Jan 1998 03:00:00 GMT  
 I need a PRESS_ANY_KEY_TO_CONTINUE function

Quote:

>I have tried:
>void press_any_key (void)
>{
>    printf("Press any key to continue....");
>    getchar();
>    printf("\n");
>}
>and I get a CODE HAS NO EFFECT warning from my IDE.
>Also, it keeps getting characters until RETURN is pressed.  I want a
>press *ANY* key function.  I have #include <stdio.h>   already executed also.
>So please give me a little help.  Thanks.
>Eric Buschelmann


Eric:
It would help to know what your target environment is.  Assuming you
are writing for a PC compatable,  you can do it this way:

        printf("Press any key to continue....");
        while(!(kbhit());               /* Loop until character available */
        printf("\n");

If you are writing code for some other system  then you can _always_
use:

        printf("Press any key to continue....");
        dummy = getch();                /* getch() waits until character available */
        printf("\n");

 -------------------------------------------------------
|  PSC, Inc                                             |
|  LazerData Products Group                             |
|                                                       |
|  1-800-843-2700                                       |
|  1-407-324-1230                 James R. Waldron      |
|  Fax: 1-407-321-3070            Director              |
|                                 Software Engineering  |

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



Sun, 11 Jan 1998 03:00:00 GMT  
 I need a PRESS_ANY_KEY_TO_CONTINUE function

Quote:

>I have tried:
>void press_any_key (void)
>{
>    printf("Press any key to continue....");
>    getchar();
>    printf("\n");
>}
>and I get a CODE HAS NO EFFECT warning from my IDE.
>Also, it keeps getting characters until RETURN is pressed.  I want a
>press *ANY* key function.  I have #include <stdio.h>   already executed also.
>So please give me a little help.  Thanks.
>Eric Buschelmann


         Replace getchar() w/ getch().

          /\ isosceles



Sun, 11 Jan 1998 03:00:00 GMT  
 I need a PRESS_ANY_KEY_TO_CONTINUE function

Quote:
>void press_any_key (void)
>{
>    printf("Press any key to continue....");
>    getchar();
>    printf("\n");
>}
>and I get a CODE HAS NO EFFECT warning from my IDE.

You were very close to the answer!

/* This little baby is by own creation, short and sweet. */

void wait(void)
{ char inchar;
  printf("\nHit any key to continue...\n");
  getche();

Quote:
}

Now, do you know anyone who might have a non-recursive binary tree inorder
traversal algorithm?  I need one badly!

/* All knowledge is available, if you know where to find it. */




*** Nothing is as sweet as a beautiful piece of code.



Sun, 11 Jan 1998 03:00:00 GMT  
 I need a PRESS_ANY_KEY_TO_CONTINUE function

Quote:
>: /* This little baby is by own creation, short and sweet. */
>: void wait(void)
>: { char inchar;
>:   printf("\nHit any key to continue...\n");
>:   getche();
>: }
>: *** Nothing is as sweet as a beautiful piece of code.
>This is certainly beautiful. I especially like the way you pointed out
>the platform dependency and the shortcut of adding char inchar. ;)

Ok, ok.  So it' s platform dependant (DOS) but it does work well.  I
copied it verbatim from my code which BTW included a char declaration that
I hadn't deleted.  I will try to be more careful next time to only quote
ANSI portable code or at least define it as such.

/* Toasted. */



*** Nothing is as sweet as a beautiful piece of code.



Mon, 12 Jan 1998 03:00:00 GMT  
 I need a PRESS_ANY_KEY_TO_CONTINUE function

Quote:

>I have tried:

>void press_any_key (void)
>{
>    printf("Press any key to continue....");
>    getchar();
>    printf("\n");
>}
>and I get a CODE HAS NO EFFECT warning from my IDE.

>Also, it keeps getting characters until RETURN is pressed.  I want a
>press *ANY* key function.  I have #include <stdio.h>   already executed also.
>So please give me a little help.  Thanks.

>Eric Buschelmann


Hello,
    just replace the getchar() by getch()

Michael



Tue, 13 Jan 1998 03:00:00 GMT  
 I need a PRESS_ANY_KEY_TO_CONTINUE function

Quote:

>Eric:
>It would help to know what your target environment is.  Assuming you
>are writing for a PC compatable,  you can do it this way:
>    printf("Press any key to continue....");
>    while(!(kbhit());               /* Loop until character available */
>    printf("\n");

This is *horrible* code for a PC.  If you're running Windows or OS/2, this
code uses every last cycle it can get its hands on - while doing nothing.
On a PC, use getch(), which will wait until a character is available.

Quote:
>If you are writing code for some other system  then you can _always_
>use:
>    printf("Press any key to continue....");
>    dummy = getch();                /* getch() waits until character available */
>    printf("\n");

Except that many platforms don't have a getch().  I have at least one
implementation where getch() waits for a newline by default.  And you leave
a newline in the buffer this way.

Please don't say "always" when you mean "hardly ever".

-s
--

proto-wizard -- C/Unix questions? Send mail for help.  No, really!
Copyright 1995 Peter Seebach.  Not for distribution through Microsoft Network.
Hypochondria is a serious illness!  For more information about H.A., write



Sun, 25 Jan 1998 03:00:00 GMT  
 I need a PRESS_ANY_KEY_TO_CONTINUE function
I normally use a "Press return to continue" function. Here's how it goes:
char x;    
printf ("Press return to continue");
x = getchar();
/* If the computer skips getchar() simply add another x = getchar(); line,
you will have two, one flushes the variable the other one waits until
return is hit*/
/* Once return has been pressed, getchar() ends and the operation may
continue */


Wed, 04 Feb 1998 03:00:00 GMT  
 I need a PRESS_ANY_KEY_TO_CONTINUE function

writes:
|> I normally use a "Press return to continue" function. Here's how it goes:
|> char x;    
|> printf ("Press return to continue");
|> x = getchar();
|> /* If the computer skips getchar() simply add another x = getchar(); line,
|> you will have two, one flushes the variable the other one waits until
|> return is hit*/

Anyone know what the above comment means?

|> /* Once return has been pressed, getchar() ends and the operation may
|> continue */

Cheers
Tanmoy
--

Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87544-0285,USA H:#3,802,9 St,NM87545
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]



Thu, 05 Feb 1998 03:00:00 GMT  
 I need a PRESS_ANY_KEY_TO_CONTINUE function

Quote:

>I normally use a "Press return to continue" function. Here's how it goes:
>char x;    
>printf ("Press return to continue");
>x = getchar();
>/* If the computer skips getchar() simply add another x = getchar(); line,
>you will have two, one flushes the variable the other one waits until
>return is hit*/
>/* Once return has been pressed, getchar() ends and the operation may
>continue */

What does this mean ^^^^^^ ???????

If your looking for a pause just use this for a pause..

 printf("Press any key to continue.");
 getch();

this will pause till a key is pressed. DOn't know what your saying bout the 'x'......

.\\ aniac



Fri, 06 Feb 1998 03:00:00 GMT  
 I need a PRESS_ANY_KEY_TO_CONTINUE function

Quote:


>>I normally use a "Press return to continue" function. Here's how it goes:
>>char x;    
>>printf ("Press return to continue");
>>x = getchar();
>>/* If the computer skips getchar() simply add another x = getchar(); line,
>>you will have two, one flushes the variable the other one waits until
>>return is hit*/
>>/* Once return has been pressed, getchar() ends and the operation may
>>continue */

Why is this causing confusion?  It sounds like he is describing the problem
you get if there are already chars in the buffer when the code reaches the
getchar.  Of course, getchar simply pulls the first char and code continues
without the expected pause.

I'm not sure just what he expects to accomplish with a second getchar, though.
I guess it would work if there was 1 char in the buffer, but what if the buffer
was empty or there were 3 chars in it?

Quote:

>What does this mean ^^^^^^ ???????

>If your looking for a pause just use this for a pause..

> printf("Press any key to continue.");
> getch();

>this will pause till a key is pressed. DOn't know what your saying bout the 'x'......

In some (DOS) compilers using non-ansi extensions, getch() may exist and
do what you say.

The c.l.c faq explains some of these issues.

--
John R Buchan           -:|:-     Looking for that elusive FAQ?  ftp to:



Fri, 06 Feb 1998 03:00:00 GMT  
 I need a PRESS_ANY_KEY_TO_CONTINUE function

Quote:

>>/* Once return has been pressed, getchar() ends and the operation may
>>continue */
>What does this mean ^^^^^^ ???????
>If your looking for a pause just use this for a pause..
> printf("Press any key to continue.");
> getch();
>this will pause till a key is pressed. DOn't know what your saying bout the 'x'......

How do you know that getch() is available on all machines? It is not
a function from the standard C library. There is a function called
getch() in curses, but this will not be very helpful for someone who
does not have curses :-(. What's wrong with asking users to press
return to continue, if you want to write interactive programs at
the tty level.

Kurt
--
| Kurt Watzka                             Phone : +49-89-2180-2158




Fri, 06 Feb 1998 03:00:00 GMT  
 I need a PRESS_ANY_KEY_TO_CONTINUE function

Quote:

> |> /* If the computer skips getchar() simply add another x = getchar(); line,
> |> you will have two, one flushes the variable the other one waits until
> Anyone know what the above comment means?

    Sounds like the neato expects the first getchar() to soak up any
    input that has been typed in advance by the user. Which is bogus.

Quote:
> Tanmoy

--

***                 All Blacks take Bledisloe Cup 34-23                 ***


Fri, 06 Feb 1998 03:00:00 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Need documentation for __unDNameEx function in MSVCR71.DLL

2. Need the pointer to a function

3. need your help: strange function declarations

4. C-beginner needs advise for string function

5. ***Newbie Needs Help With Functions Program ***

6. non-novice needs help with variable arguements va_arg to a function

7. Need help calling functions

8. Help needed to move some specific work into a more common function

9. Need macro equivalent for function

10. Need time zone conversion routine/program/function that is callable, pcumming

11. TIME FUNCTION -- NEED help compiling

12. Need help for writing a function returning pointer

 

 
Powered by phpBB® Forum Software