#include <stdio.h>
void main()
{
int a=1;
char c;
x:for(a=1;a!=0;a++)
{
printf("Hello\n");
c=getch();
if(c=='n')
exit(0);
else
goto x;
}
}
//请仅使用主要运算符协助我完成此程序
最佳答案
这有点不同,向您展示一个简单的解决方案。但是,如果不允许您使用 kbhit
,您就会被卡住。
#include <stdio.h>
#include <conio.h> // include the library header
int main(void) // correct signature for main
{
int c = 0; // note getch() returns `int` type
while(c != 'n') // until correct key is pressed
{
do { // forever
printf("Hello\n");
} while(!kbhit()); // until a key press detected
c = getch(); // fetch that key press
}
return 0;
}
请记住,它只测试小写的 n
。
关于c - 无限循环直到按下键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40639720/