Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pause in Program 1

Status
Not open for further replies.

WarrenB

Programmer
Feb 7, 2001
38
GB
How would I generate a pause in a program until a key is pressed (i.e. press any key to continue). Thanks in advance :) Warren Brown
wazzer@btinternet.com
 
Hi Warren,
u could use while(!KBHit()) in that case, try it out.
Regards,
Hemant.
 
Hi Kapadia and aphrodita.

i did not start this thread but im interested in the case anyway.

aphrodita, i tried ur suggestion but it does not seem to work. i think getc (i need #include <stdio.h> for it) takes a FILE *stream formal parameter so it doesn't work with cin.
doing something wrong?

Kapadia,
i need to #include some .h file...? KBHit() must be some function, most probably inherited from C, is that a correct guess? i havent been able to find the right .h file to include though. some help...

thanks to both of you! :)
Avendeval Sedai
[sub]yavoor@yahoo.com[/sub]

 
Sedai is right about my case:
Instead you have to use this

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

void main()
{
cout << &quot;Please enter something to continue&quot;<<endl;
char c;
c = getch();
} Best Regards,

aphrodita@mail.krovatka.ru {uiuc rules}
 
:) thanks aphrodita! :)

it's working fine now. Avendeval Sedai
[sub]yavoor@yahoo.com[/sub]

 
/* KBHIT.C: This program loops until the user
* presses a key. If _kbhit returns nonzero, a
* keystroke is waiting in the buffer. The program
* can call _getch or _getche to get the keystroke.
*/

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

void main( void )
{
/* Display message until key is pressed. */
while( !_kbhit() )
_cputs( &quot;Hit me!! &quot; );

/* Use _getch to throw key away. */
printf( &quot;\nKey struck was '%c'\n&quot;, _getch() );
_getch();
}

This sample from MSDN
 
hi,
Sorry for being out of touch,Any way using kbHit() one stays in the loop unless a specific key is pressed. Say u want to exit the program or the loop on 'Escape' or 'Enter' key then
Code:
while((!kbhit()==13)||(!kbhit== 26))
{
part of code
}

or say u want to use[y/n] [yes] or [no] then 
 while(!kbhit()=='n')
{
 part of code...
}
I guess this will help u.
Hemant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top