我花了过去几周的时间开发一个基本上依赖于 getch() 函数的应用程序,然后我最近决定更新 Visual Studio,却发现我的程序完全损坏并且不再工作。
这是我所拥有的一个简单示例:
main(){
while (1){
//The program loops until 's' is pressed (this still works)
com=getch();
if(com=='s'){
//The program used to stop here and wait for input (now it doesn't)
com=getch();
if(com=='d') printf("Victory!\n");
else break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
*这不是我程序的一部分,这只是一个示例,需要按“s”然后按“d”才能获胜
现在,这在我更新之前就起作用了,我知道,因为我花了 50 多个小时来开发该程序,它的工作方式如下:
程序将到达 getch() 并等待我的输入,如果我按 's',if 会触发执行其功能,然后它将到达第二个 getch() 并等待我的输入,因此您需要按 'd '并获胜!
要点是,它曾经在每次 getch() 时等待我的输入!
但现在,新的更新它等待第一个 getch() 但 complitley 忽略了第二个,这很好地结束了程序并且没有办法获胜。
也许我做了什么,也许 getch() 现在是非法的,我不知道,我晚餐不高兴,我不知道该怎么办......
无论如何,提前致谢,如果您还有什么需要了解的,请随时询问。我是编程新手,所以不要期望任何高水平的答案!
编辑:我花了几个小时来探索这里的代码:
#include <conio.h>
#include <stdio.h>
main(){
char com;
while(1){
com=getch();
printf("You pressed: %c\n",com); …Run Code Online (Sandbox Code Playgroud)