Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



C : Use of kbhit()

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 29-01-2010
Member
 
Join Date: Jan 2010
Posts: 26
C : Use of kbhit()
  

Hello, How are you all? I am the student of the MscIT. I have the knowledge of the C language. I want to know about the kbhit() function of the C language. I also want to know about the For what purpose the kbhit() function can be used and how they can be initialized or invoked. So, Anyone is there who can help me to know about the kbhit() function? As soon as possible provide me the solution. i am waiting for your reply!!!!!!!!!

Reply With Quote
  #2  
Old 29-01-2010
Member
 
Join Date: May 2008
Posts: 2,376
Use of kbhit()

To check or test the keystroke that whether the keystrokes are currently available or not the kbhit() function can be used. To obtain the keystroke getch(0 or getche(0 function can be used, whenever the one of the keystroke can be available. Until a keystroke is available the kbhit() function can be called continuously with a stand-alone program. You have to note that loops involving the kbhit() function can not be recommended in multitasking systems. The following is the syntax of the kbhit() function :
#include <conio.h>
int kbhit( void );
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #3  
Old 29-01-2010
Member
 
Join Date: Feb 2008
Posts: 1,842
C : Use of kbhit()

The following sample program describes you about the kbhit() function :
#include <stdio.h>
#include <conio.h>
int main(void)
{
double amt;
amt = 0.20;
cprintf(" Printing 6-percent tax table\n\r ");
cprintf(" Press a key to stop.\n\n\r ");
do {
cprintf(" Amount : %f, Tax : %f\n\r ", amount, amount * 0.06);
if(kbhit())
break;
amt = amt + 0.40;
} while(amt < 200.0);
return 0;
}
Reply With Quote
  #4  
Old 29-01-2010
Member
 
Join Date: Jan 2008
Posts: 1,511
kbhit() function : Program

The following program demonstrate that program loops until a any key is pressed or a count can be exceeded :
#include <stdio.h>
#include <conio.h>
void main()
{
unsigned long j;
printf( " Program looping. Press any key.\n " );
for( j = 0; j < 20000; j++ ) {
if( kbhit() ) {
getch();
break;
}
}
}
Reply With Quote
  #5  
Old 29-01-2010
Member
 
Join Date: Apr 2008
Posts: 1,946
Re: C : Use of kbhit()

Sample Example :
#include <conio.h>
#include <stdio.h>
int main( void )
{
while( !_kbhit() )
_cputs( "Hit me!! " );
printf( "\nKey struck was '%c'\n", _getch() );
}
Output :
Hit me!! Hit me!! Hit me!! Hit me!! Hit me!! Hit me!! Hit me!!
Key struck was 'q'
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search



All times are GMT +5.5. The time now is 03:23 PM.