c语言识别按了esc键_c语言,汉诺塔程序,如何按esc键退出程序

这是一篇关于C语言实现汉诺塔程序的博客,博主在结课设计中遇到问题,需要在运行程序时能够通过按下ESC键退出。程序使用TC2.0编译,博主请求帮助修改代码以实现这一功能。
摘要由CSDN通过智能技术生成

我们c语言结课,做结课设计。做汉诺塔。网上找了个程序,改了一下,就差在任意情况下按esc退出不会弄了。麻烦高手帮我在我的程序上改一个esc退出,谢谢~~~~是在我的程序上改,不是网上找个那个while的死循环程序复制上来,改好了100分一定会给的,帮个忙,十分感谢了。老师让用t

我们c语言结课,做结课设计。做汉诺塔。网上找了个程序,改了一下,就差在任意情况下按esc退出不会弄了。麻烦高手帮我在我的程序上改一个esc退出,谢谢~~~~是在我的程序上改,不是网上找个那个while的死循环程序复制上来,改好了100分一定会给的,帮个忙,十分感谢了。老师让用tc2.0,不让用vc6.0.。。。。#include #include #include #include /* --------------------------------------------------------------------------------------- */#define PATH "e:\\TC\\BGIOBJ"#define N 100/* --------------------------------------------------------------------------------------- */int x[N][2], y[N][2] ,s;int countA, countB, countC ;/* --------------------------------------------------------------------------------------- */void init(int numT) ;void HanoiAuto(char from,char to,char aux,int n);void Hanoi(char from, char to, char aux, int n) ;void movTower(int n, char from, char to) ;void movup(int arrayE, int x1, int x2) ;void movdown(int arrayE, int x1, int x2, int countN) ;void movright(int arrayE, int x, int n) ;void movleft(int arrayE, int x, int n) ;/* --------------------------------------------------------------------------------------- */void main(){int gdriver=DETECT, gmode,n,a ;initgraph(&gdriver, &gmode, PATH) ;printf("choose the speed,100 or 200 or 300 or 400\n");scanf("%d",&s);printf("enter the number of dish\n");scanf("%d",&n);countA=n ;countB=0 ;countC=0 ;printf("1.handly\ to\n");scanf("%d",&a);clearviewport();init(n);getch();if(a==1)Hanoi('A', 'C', 'B', n) ;elseHanoiAuto('A','C','B',n);getch() ;closegraph() ;}/* --------------------------------------------------------------------------------------- */void init(int numT){int i ;int count=0 ;bar(10, 70, 629, 409) ;/* the border */setfillstyle(1, 0) ;bar(30, 359, 609, 369) ;/*the di */bar(121, 150, 131, 358) ;/*the lef */bar(314, 150, 324, 358) ;/*the mid */bar(507, 150, 517, 358) ;/*the rig */setcolor(8) ;for(i=numT-1 ; i>=0 ; i--) /*pan zi*/{ x[count][0]=121-(numT-i)*4 ; x[count][1]=131+(numT-i)*4 ; y[count][0]=348-i*11 ; y[count][1]=358-i*11 ; rectangle(x[count][0], y[count][0], x[count][1], y[count][1] ) ; count++ ;}}/* --------------------------------------------------------------------------------------- */void HanoiAuto(char from,char to,char aux,int n){if(n==1)movTower(1,from,to);else { HanoiAuto(from,aux,to,n-1); movTower(n,from,to); HanoiAuto(aux,to,from,n-1); }}/* --------------------------------------------------------------------------------------- */void Hanoi(char from, char to, char aux, int n){if(n==1) { getch(); movTower(1, from, to) ; }else{ Hanoi(from, aux, to, n-1) ; getch(); movTower(n, from, to) ; Hanoi(aux, to, from, n-1) ;}}/* --------------------------------------------------------------------------------------- */void movTower(int n, char from, char to){int arrayE ;arrayE=n-1 ;moverel(30,400);if(from=='A' &&

展开

全部

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值