首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

哪位高手帮忙改一下异常

2013-10-23 
谁帮忙改一下错误迷宫问题代码:#include stdio.h#include stdlib.h#include malloc.h#include stri

谁帮忙改一下错误
迷宫问题代码:

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#define m 6
#define n 8
int maze[m+2][n+2];
typedef struct {
int x,y;
}item;
item move[8]={{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1}};
typedef struct{
int x,y,d;
}datatype;
datatype temp;
#define FALSE 0
#define TRUE 1
typedef struct node{
  int a,b,c;
  struct node *next;

}SeqStack;
SeqStack * Init_SeqStack()
{
   SeqStack *top;
   top->next=NULL;
   return top;
}
int Push_SeqStack(SeqStack *top,datatype temp)
{
      SeqStack *p;
      p=(SeqStack *)malloc(sizeof(SeqStack));
      if(p==NULL)
        return FALSE;
        p->a=temp.x;
        p->b=temp.y;
        p->c=temp.d;
        p->next=top->next;
        top->next=p;
        return TRUE;
}
int IsEmpty(SeqStack *top)
{
     if(top->next==NULL)
         return TRUE;
     return FALSE;
}
int Pop_SeqStack(SeqStack *top,datatype *s)
{
    SeqStack *p;
    if(IsEmpty(top))
       return FALSE;
    p=top->next;
    s->x=p->a;
    s->y=p->b;
    s->d=p->c;
    top->next=p->next;
    free(p);
    return TRUE;
}
//迷宫
int path(int maze[m][n],item move[8])
{
    SeqStack *s;
    int x,y,d,i,j;
    s=Init_SeqStack();
    temp.x=1;
    temp.y=1;
    temp.d=-1;
    Push_SeqStack(s,temp);
    while(!Empty_SeqStack(s))
    {
           Pop_SeqStack(s,&temp);
           x=temp.x;
           y=temp.y;
           d=temp.d+1;
           while(d<8)
           {
               i=x+move[d].x;
               j=y+move[d].y;
               if(maze[i][j]=0)
               {
                      temp={x,y,d};
                      Push_SeqStack(s,temp);
                      x=i;
                      y=j;
                      maze[x][y]=-1;
                      if(x==m && y==n)
                         return 1;
                         else
                          d=0;
               }
               else
                  d++;
           }
    }
    return 0;

}
int main()
{
   int i,j,f;
   for(i=0;i<8;i++)
     for(j=0;j<10;j++)
       maze[i][j]=1;
       maze[1][1]=0;


       maze[2][2]=0;
       maze[3][3]=0;
       maze[3][4]=0;
       maze[3][5]=0;
       maze[3][6]=0;
       maze[3][7]=0;
       maze[4][5]=0;
       maze[5][6]=0;
       maze[5][7]=0;
       maze[5][8]=0;
       maze[6][8]=0;
       f=path(maze[m+2][n+2],move[]);
       if(1==f)
         printf("迷宫有出路");
         else
           printf("迷宫没出路");
     return 0;
}


/main.c|82|错误: expected expression before ‘{’ token|
/main.c|117|错误: expected expression before ‘]’ token|
[解决办法]
               if(maze[i][j]=0)  // 这里应该是maze[i][j]==0
               {
                      temp={x,y,d}; //结构体这种初始化方式是错误,改成 temp.x=x ;temp.y=y;temp.d=d
[解决办法]
参考我写的代码
这句话传参应该写错了吧 你自己想想
int path(int maze[m][n],item move[8])



 
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
//
//实现魔塔地图读取器 ,地图编辑器 编辑好地图后存入txt文件  本程序实现读取
//
bool write_map(char *filename,char (*pos)[14])
{
    FILE * fd;
    int i, j ;
    fd = fopen(filename,"w");

    for(i = 0 ; i < 14 ; i++)
        for(j = 0; j < 14 ;j++)
                  fprintf(fd,"%d ",pos[i][j]);//必须有空格 要不读的时候会出问题

    fclose(fd);

    return true;

}
bool read_map(char *filename,char (*pos)[14])
{
    FILE * fd;
    int i, j ;
    fd = fopen(filename,"r");

    for(i = 0 ; i < 14 ; i++)
        for(j = 0; j < 14 ;j++){

                  fscanf(fd,"%d",&pos[i][j]);
        }
    fclose(fd);

    return true;
}
int main()
{
    int i ;
    int j ;

    int8_t pos[14][14] ;
    int8_t pos1[14][14] ;
   read_map("E:\\write.txt",pos1);

    for(i = 0 ; i < 14 ;i++)
        for(j = 0 ; j < 14 ;j++){
            printf("%d\n",pos1[i][j]);
        }
   // write_map("E:\\wtite.txt",pos1);

    return 0;
}

[解决办法]
改成这样试试
int path(int (*maze)[10],item move[8])
{



}

热点排行