如何终止 Turbo C 中的无限循环?
我陷入了无限循环。我怎样才能终止这个循环?我尝试使用/按 Cntrlc 但没有任何反应。我不知道如何阻止它。
main()
{
while (1)
{
char ch;
printf("Enter a character: \n");
ch = getche();
printf("\nThe code for %c is %d.\n", ch, ch);
}
}
I get stuck in an infinite loop. How can I terminate this loop? I tried to use/press Cntrlc but nothing happens. I don't know how to stop it.
main()
{
while (1)
{
char ch;
printf("Enter a character: \n");
ch = getche();
printf("\nThe code for %c is %d.\n", ch, ch);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
CTRLBREAK 可能适用于此。我模糊地记得 CTRLC 并不总是适用于 Borland 产品。
不过,那是很久以前的事了,所以我必须从非常深刻的记忆中检索它,这些记忆可能已经有些褪色了:-)
我的问题是:为什么还有人在使用 Turbo C 时已经好多了还有同样便宜的解决方案吗?像 gcc(例如 Code::Blocks 中的)甚至 Microsoft Visual C Express。
CTRLBREAK will probably work for this. I have a vague recollection that CTRLC did not always work with the Borland products.
Though, that was a long time ago so I had to retrieve that from very deep memory, which may have faded somewhat :-)
My question for you is: Why is anyone still using Turbo C when much better and equally cheap solutions are available? Like gcc (such as in Code::Blocks) or even Microsoft Visual C Express.
你需要一个条件来打破你的 while 循环。
就像这样,
如果输入的字符是“q”,或者如果您坚持使用 while(1),则可以使用“break”关键字:
you need a condition to break out of your while loop.
so like,
would break out if the entered char was 'q', or if you insist on while(1), you could use the "break" keyword:
如果您只想暂停 Turbo C 中的无限循环,请按 BREAK。如果您想返回 Turbo C 中的程序编辑器,请按 CTRL+BREAK。它将返回编辑您的程序。
是的,我尝试过这个并且有效!
If you want to just pause your infinite loop in Turbo C then press the BREAK. If you want to get back to the editor of your program in Turbo C then press CTRL+BREAK. It will return back to editing your program.
Yes, I tried this and it works!
CTRL-Break、Break 和 CTRL-C 对我不起作用,但 CTRL-ESC-ESC 对我有用! (这是在 Borland C++ 3.1 中使用几乎相同的代码进行测试的)。
CTRL-Break, Break and CTRL-C didn't work for me, but CTRL-ESC-ESC did! (This was tested with almost identical code in Borland C++ 3.1).
没有办法停止无限循环。但是,您可以在循环内部添加一个导致循环中断的条件,或者您可以在循环内部调用 exit() 函数,这将终止您的程序。
There is no way to stop an infinite loop. However, you can add a condition inside of the loop that causes it to break, or you can call the exit() function inside of the loop, which will terminate your program.