-
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!!!!!!!!!
-
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 );
-
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;
}
-
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;
}
}
}
-
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'
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Page generated in 1,711,713,022.78036 seconds with 16 queries
Bookmarks