谁帮忙改一下错误

Shadow0418 2013-10-21 11:06:15
迷宫问题代码:
#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|
...全文
156 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
做或不做 2013-10-22
  • 打赏
  • 举报
回复
改成这样试试 int path(int (*maze)[10],item move[8]) { }
做或不做 2013-10-22
  • 打赏
  • 举报
回复
参考我写的代码 这句话传参应该写错了吧 你自己想想 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;
}
Shadow0418 2013-10-21
  • 打赏
  • 举报
回复
用Codeblocks + gcc我改好后。还是有错: /main.c|119|警告: 传递‘path’的第 1 个参数时在不兼容的指针类型间转换 [默认启用]| /main.c|61|附注: 需要类型‘int (*)[8]’,但实参的类型为‘int (*)[10]’| /main.c|26|警告: 此函数中的‘top’在使用前未初始化 [-Wuninitialized]| ||=== Build finished: 3 errors, 0 warnings ===|
#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(!IsEmpty(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=x;
                      temp.y=y;
                      temp.d=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,move);
       if(1==f)
         printf("迷宫有出路");
         else
           printf("迷宫没出路");
     return 0;
}

  • 打赏
  • 举报
回复
f=path(maze[m+2][n+2],move[]); //这种传实参的方式也不对呀, f=path(maze,move)
  • 打赏
  • 举报
回复
if(maze[i][j]=0) // 这里应该是maze[i][j]==0 { temp={x,y,d}; //结构体这种初始化方式是错误,改成 temp.x=x ;temp.y=y;temp.d=d

69,368

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧