#if 1
// When keyboard input is received, * is displayed in the window.
#include <stdio.h>
#include <conio.h>
int main()
{
int key;
while (1)
{
if (_kbhit())
{
key = _getch();
printf("%c", 42);
}
else;
}
}
#if 1
// When keyboard input is received, * is output to the window endlessly
#include <stdio.h>
#include <conio.h>
int main()
{
int key;
while (1)
{
if (_kbhit())
{
printf("%c", 42);
}
else;
}
}
different from the first sentence
Without _getch() as in the second statement,
When I receive keyboard input once, * is output endlessly, why is that?
key = _getch();
If you don't read the keyboard value
if (_kbhit())
Because the condition is continuously satisfied, the if() statement continues to be executed.