A simple question about kbhit() and gatch(): I want to makde a code about switch
ID: 3544510 • Letter: A
Question
A simple question about kbhit() and gatch():
I want to makde a code about switch two pictures by use kbhit() and gatch();
Like when I pressed 'x' , it will showing picture 1 in windows BGI, if not, it will showing picture 2.
There is I tried to do. But it doesnt work:
char ch = getch();
if (kbhit()) { getch();
switch (ch){
case(120) : readimagefile("PIX\flipper_up.jpg", 0, 0, 640, 480);
}
readimagefile("PIX\flipper_down.jpg", 0, 0, 640, 480);
break;}
please tell me the correct answer and explain it. Thank you.
If you need more details just comment there.
Explanation / Answer
Please find working code below, comments are inline. Let me know via comments if you need more help. Hope it helps. Thanks
// Declare the character variable:
char ch;
// Wait till a key is pressed
while (kbhit() != 0)
{
// do nothing
}
// Read the key character
ch = getch();
// Do action as per need
if(ch == 'x')
{
readimagefile("PIX\flipper_up.jpg", 0, 0, 640, 480);
}
else
{
readimagefile("PIX\flipper_down.jpg", 0, 0, 640, 480);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.