分类：电脑/网络-软件
问题：如何用tc做一个小软件。并示范一样本人。现在大一，老师要我们用t 
本人。现在大一，老师要我们用tc做一个小。那一位高人能做一个示范说明。
回答：程序目的:输入一个任意大小的迷宫,用栈求出一条走出迷宫的路径,并显示在屏幕上。程序实现:可以实现载入迷宫和保存迷宫,附带文件中有4个测试迷宫路径的文件test1~4.dd。请将这些文件拷贝到TC当前目录下,或者在载入时写明完全路径。由于屏幕大小的限制,当用户自己输入迷宫时一定要注意:迷宫大小是有限制的,不小于4*3,不大于30*20。否则会出现错误信息。输入开始时全是墙,用上下左右键移动,用Del键删除墙,形成通路,用Enter键添加墙。输入结束时可以将迷宫保存下来,以dd为扩展名。输入完毕时用F9键来得到结果,找到路径时,屏幕下方会出现Pathfound,否则出现Pathnotfound。程序经TurboC2.0编译调试成功。运行时不用添加任何运行库。不可以在VC上编译。下载DOS版和windows版的迷宫全部代码用户名:migong----------------------------------------------------------------------------------/*MazePathDemoBYTurboC2.0Copyright(c)RoverUnion.Allrightreserved. */#include<stdio.h>#include<stdlib.h>#include<malloc.h>#include<conio.h>#include<dos.h>#defineOK1#defineERROR0#defineTRUE1#defineFALSE0#defineF90x43#defineEsc0x1b#defineDel0x53#defineHome0x47#defineEnd0x4f#defineSpace0x20#defineUp0x48#defineDown0x50#defineLeft0x4b#defineRight0x4d#defineEnter0x0d#defineF20x3c#defineF30x3d#defineSTACK_INIT_SIZE200#defineSTACKINCREMENT10typedefintBoolean;typedefintStatus;typedefstruct{intx;inty;}PosType;typedefstruct{intord;PosTypeseat;intdi;}SElemType;typedefstruct{inttd;intfoot;intmark;}MazeType;typedefstruct{SElemType*base;SElemType*top;intstacksize;}Stack;intMaze[20][30];MazeTypemaze[20][30];PosTypeStartPlace;PosTypeEndPlace;intcount;intm,n;Booleanb_start=FALSE,b_end=FALSE;voidCreatMaze(void);StatusSaveMaze(char*filename);StatusLoadMaze(char*filename);voidError(char*message);StatusInitStack(Stack*s);StatusDestroyStack(Stack*s);StatusClearStack(Stack*s);BooleanStackEmpty(Stack*s);intStackLength(Stack*s);StatusPush(Stack*s,SElemTypee);SElemTypePop(Stack*s,SElemTypee);StatusGetTop(Stack*s,SElemType*e);StatusStackTraverse(Stack*s,Status(*visit)(SElemType*se));BooleanPass(PosTypecurpos);voidMarkPrint(PosTypeseat);voidFootPrint(PosTypecurpos);PosTypeNextPos(PosTypeseat,intdi);StatusMazePath(PosTypestart,PosTypeend);voidCreatMaze(void)/*Formthemaze.*/{voidError(char*message);StatusSaveMaze(char*filename);StatusLoadMaze(char*filename);inti,j;intx,y;charc;charsavename[12],loadname[12];Booleanflag=FALSE,load=FALSE;clrscr();printf("Menu:\n\n");printf("1.LoadMazefile:(*.dd)\n\n");printf("2.InputMaze:\n\n");printf("Inputyourchoice:");do{c=getch();switch(c){case''''''''''''''''''''''''''''''''1'''''''''''''''''''''''''''''''':putch(''''''''''''''''''''''''''''''''1'''''''''''''''''''''''''''''''');break;case''''''''''''''''''''''''''''''''2'''''''''''''''''''''''''''''''':putch(''''''''''''''''''''''''''''''''2'''''''''''''''''''''''''''''''');break; (1);exit(1); }}while(c!=''''''''''''''''''''''''''''''''1''''''''''''''''''''''''''''''''&&c!=''''''''''''''''''''''''''''''''2'''''''''''''''''''''''''''''''');if(c==''''''''''''''''''''''''''''''''1''''''''''''''''''''''''''''''''){printf("\n\nLoadName:");scanf("%s",loadname);if(LoadMaze(loadname)){sleep(1);load=TRUE;}else{gotoxy(1,9);printf("Loadfail!");}}if(!load){printf("\nInputthemaze''''''''''''''''''''''''''''''''ssize:\n");printf("\nInputLength:\n");scanf("%d",&m);printf("\nInputWidth:\n");scanf("%d",&n);if(m<4||n<4)Error("Input");if(m>30||n>20)Error("Mazetoolarge");for(i=0;i<30;i++)for(j=0;j<20;j++)Maze[j][i]=2;StartPlace.x=0;StartPlace.y=0;EndPlace.x=0;EndPlace.y=0;clrscr();printf("\n");for(i=1;i<=n;i++){for(j=1;j<=m;j++){printf("#");Maze[i-1][j-1]=0;}printf("\n");}}gotoxy(65,5);printf("''''''''''''''''''''''''''''''''#'''''''''''''''''''''''''''''''':Wall");gotoxy(65,7);printf("");gotoxy(65,9);printf("");gotoxy(65,11);printf("Delete");gotoxy(65,13);printf("Enter");gotoxy(65,15);printf("Save");gotoxy(65,17);printf("");gotoxy(65,19);printf("");gotoxy(4,3);x=4;y=3;do{c=getch();switch(c){ (y>3){y--;gotoxy(x,y);}break; (y<n){y++;gotoxy(x,y);}break; (x>4){x-=2;gotoxy(x,y);}break; (x<2*m-2){x+=2;gotoxy(x,y);}break; (y-2==StartPlace.y&&x/2-1==StartPlace.x)b_start=FALSE;if(y-2==EndPlace.y&&x/2-1==EndPlace.x)b_end=FALSE;putch('''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''');Maze[y-2][x/2-1]=1;gotoxy(x,y);break; (y-2==StartPlace.y&&x/2-1==StartPlace.x)break;if(y-2==EndPlace.y&&x/2-1==EndPlace.x)break;putch(''''''''''''''''''''''''''''''''#'''''''''''''''''''''''''''''''');Maze[y-2][x/2-1]=0;gotoxy(x,y);break; (Maze[y-2][x/2-1]&&!b_start){StartPlace.x=x/2-1;StartPlace.y=y-2;putch(''''''''''''''''''''''''''''''''S'''''''''''''''''''''''''''''''');gotoxy(x,y);b_start=TRUE;}break; (Maze[y-2][x/2-1]&&!b_end){EndPlace.x=x/2-1;EndPlace.y=y-2;putch(''''''''''''''''''''''''''''''''E'''''''''''''''''''''''''''''''');gotoxy(x,y);b_end=TRUE;}break; (2,22);printf("exit");sleep(1);exit(1);caseF9:if(b_start&&b_end)flag=TRUE;break;caseF2:gotoxy(2,22);printf("Savename:");scanf("%s",savename);gotoxy(2,22);if(SaveMaze(savename))printf("SaveOK!");elseprintf("Savefail!");sleep(1);gotoxy(2,22);printf("");gotoxy(x,y);break; }}while(!flag);for(i=0;i<30;i++)for(j=0;j<20;j++){maze[j][i].td=Maze[j][i];maze[j][i].mark=0;maze[j][i].foot=0;}}StatusLoadMaze(char*file)/*Themazehasbeenloaded.*/{FILE*fp;char*buffer;charch;inti=0,j,k;Booleanlen=FALSE,wid=FALSE;if((fp=fopen(file,"r"))==NULL)returnERROR;buffer=(char*)malloc(600*sizeof(char));ch=fgetc(fp);while(ch!=EOF){buffer[i]=ch;i++;ch=fgetc(fp);}m=30;n=20;for(i=0;i<600;i++){j=i/30;k=i%30;if(buffer[i]==''''''''''''''''''''''''''''''''2''''''''''''''''''''''''''''''''&&!len){m=i;len=TRUE;}if(k==0&&buffer[i]==''''''''''''''''''''''''''''''''2''''''''''''''''''''''''''''''''&&!wid){n=j;wid=TRUE;}switch(buffer[i]){case''''''''''''''''''''''''''''''''0'''''''''''''''''''''''''''''''':Maze[j][k]=0;break;case''''''''''''''''''''''''''''''''1'''''''''''''''''''''''''''''''':Maze[j][k]=1;break;case''''''''''''''''''''''''''''''''2'''''''''''''''''''''''''''''''':Maze[j][k]=2;break;case''''''''''''''''''''''''''''''''3'''''''''''''''''''''''''''''''':Maze[j][k]=1;StartPlace.x=k;StartPlace.y=j;b_start=TRUE;break;