无尽剑圣:一个马踏棋盘的C语言程序 ,好多错误,帮我看看啊,谢谢

来源:百度文库 编辑:高校问答 时间:2024/05/02 07:47:27
#include "stdio.h"
#define maxstep 40
typedef struct{
int x[maxstep];
int y[maxstep];
int top;
int base;
}Stack;
void init(Stack *s)
{s->base=0;
s->top=0;
}
void push(Stack *s,int x,y)
{
s->x[s->top]=x;
s->y[s->top]=y;
s->top=s->top+1;
}
void pop(Stack* s)
{
s->top=s->top-1;
}
main(){
int step[maxstep];
int xx;
int yy;
int c;
int i;
Stack s;
init(&s)
for (i=1;i<=maxstep;i++){
step[i]=1;}
scanf("%d,%d\n",&xx,&yy);
push (&s,xx,yy);
while(s->top<=maxstep){
switch (step[s->top-1])
case 1:xx=xx+2;yy=yy+1;
case 2:xx=xx+2;yy=yy-1;
case 3:xx=xx+1;yy=yy+2;
case 4:xx=xx+1;yy=yy-2;
case 5:xx=xx-2;yy=yy+1;
case 6:xx=xx-2;yy=yy-1;
case 7:xx=xx-1;yy=yy+2;
case 8:xx=xx-1;yy=yy-2;
case 9:printf ("error");}
for (i=1;i<=s->top;i++){
if (s->x[s->top-1]==xx&&s->y[s->top-1]==yy)
c=0;}
if (xx>8||x<1||yy>8||yy<1||c=0){
pop(s);
step[s->top]=step[s->top]+1;
c=1;}
printf ("%d",s->x[5]);
}}