Home > Back-end >  C an infinite loop
C an infinite loop

Time:06-09

Write a program to constantly refresh the output 123456789, how to press enter to stop this infinite loop? (refresh type is similar to the for (;; ) {printf (" 123456789 "); })

CodePudding user response:

 # include & lt; Windows. H> 
Int main ()
{
while (! GetAsyncKeyState (13))//the corresponding key yourself for ASCII
{
Printf (" 123456789 \ n ");
Sleep (50);
}

return 0;
}

CodePudding user response:

Can use multithreading, semaphore to implement;

The main thread receives input set a variable, the child thread print (infinite loop) and determine a variable;

CodePudding user response:

reference 2 building self-confidence boy reply:
can use multithreading, semaphore to implement;

The main thread receives input set a variable, the child thread print (infinite loop) and determine a variable;

I want to at the same time in an infinite loop, press enter to exit the refresh

CodePudding user response:

reference 1st floor datoulaile123 response:
 # include & lt; Windows. H> 
Int main ()
{
while (! GetAsyncKeyState (13))//the corresponding key yourself for ASCII
{
Printf (" 123456789 \ n ");
Sleep (50);
}

return 0;
}

CodePudding user response:

I also come to a
 # include & lt; Conio. H> 
# include
# include

Int main ()
{
While (true)
{
If (_kbhit ()) {
If (_getch ()==13) {
break;
}
}
Printf (" 123456789 \ n ");
Sleep (500);

}
return 0;
}

CodePudding user response:

reference 5 floor. Cool west wing reply:
I also came to a
 # include & lt; Conio. H> 
# include
# include

Int main ()
{
While (true)
{
If (_kbhit ()) {
If (_getch ()==13) {
break;
}
}
Printf (" 123456789 \ n ");
Sleep (500);

}
return 0;
}

To study the

CodePudding user response:


I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related