ef-eve 2015-06-14 09:41 采纳率: 66.7%
浏览 1928

程序运行跳出来这个 什么问题??

it stopped with signal SIGSEGV,Segmentation fault

windows.h stdio.h stdlib.h stdio.h
-----------------------------------------------------以下正文

int xnum;
int ynum;
int a[100][100];
#define X0 100
#define Y0 100
#define WIDTH 20
typedef struct
{
int x;
int y;
}NODE;
typedef struct
{
NODE nownode;
NODE prenode;
int dir;
}GRID;

NODE start;
NODE end;
GRID grid;

//-------------------------------顺序栈
class Stack
{
private:

  int size;

 public:

   NODE *p;
   int top;
   Stack(int n=0);
   ~Stack();
   bool isEmpty();
   bool isFull();
   bool push(const NODE k);
   bool pop();

};

Stack::Stack(int n)
{
p=0;
if(n>0)
p=new NODE[n];
size=n;
top=-1;
}
Stack::~Stack(){
delete []p;
size=0;
top=-1;
}
bool Stack::isEmpty(){
return(top==-1);
}
bool Stack::isFull(){
return(top>=size-1);

}
bool Stack::push(const NODE k){
if(!isFull()){
top++;
p[top]=k;
return true;
}
return false;
}
bool Stack::pop(){
if(!isEmpty()){
NODE k=p[top];
top--;
return 1;
}
return 0;
}

//。-----------------------------画框
void Init()
{
FILE* fp;
fp=fopen("mice.txt","r");
fscanf(fp,"%d%d%d%d%d%d",&xnum,&ynum,&start.x,&start.y,&end.y,&end.x);//24 24 1 1 24 1
int i,j;
for(j=0;j<=ynum+1;j++)
for(i=0;i<=xnum+1;i++)
a[j][i]=1;
for(j=1;j<=ynum;j++)
for(i=1;i<=xnum;i++)
fscanf(fp,"%d",&a[j][i]);
fclose(fp);

grid.nownode =start;//--------------初始位置 (1,1) 

}

void reaction(Stack path,int x,int y){
grid.nownode.x=x;
grid.nownode.y=y;
path.push(grid.nownode);
//PrintNum(120,50,grid.nownode.x);
//PrintNum(140,50,grid.nownode.y);

        //DrawRectangle(X0+grid.nownode.y*WIDTH,Y0+grid.nownode.x*WIDTH,X0+(grid.nownode.y+1)*WIDTH,Y0+(grid.nownode.x+1)*WIDTH,MOUSECOLOR);

}

int MouseMove(Stack path)
{

int x,y;
x=grid.nownode.x;
y=grid.nownode.y;//--------------现在位置 


if (end.x==x && end.y==y){
        grid.nownode.x=x;
        grid.nownode.y=y;
        path.push(grid.nownode);
        return 1;

}

else{
    a[x][y]=1;//------------------------------------------------似乎指出的是这里

   if(a[x][y+1]==0)
       reaction(path,x,y+1);
   else if(a[x+1][y]==0)
     reaction(path,x+1,y);
   else if(a[x][y-1]==0)
       reaction(path,x,y-1);
   else if(a[x-1][y]==0)
       reaction(path,x-1,y);
   else
       { 
       path.pop();
       grid.nownode.x=path.p[path.top].x;   //上一个值作现在位置 
       grid.nownode.y=path.p[path.top].y;
       }  

}
return 0;

}

int main(){

Init();
Stack path(2000);        //---------------------//创建顺序表 

path.push(start);
int x,y;
x=grid.nownode.x;
y=grid.nownode.y;//--------------现在位置 

while(end.x!=x || end.y!=y)
MouseMove(path);

for(int i=0; i<=path.top;i++)
a[path.p[path.top].x][path.p[path.top].y]=2;

for(int i=0;i<=xnum+1;i++) 

{
for(int j=0;j<=ynum+1;j++)
printf("%d",a[i][j]);
printf("\n");
}
scanf("%d",&x);
return 0;
}

---------------------------------------------------mice.txt文件 (迷宫问题 C-FREE下)
24 24 1 1 24 1
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0

  • 写回答

5条回答 默认 最新

  • 帘卷西风 博客专家认证 2015-06-14 14:07
    关注

    Linux系统的吧,可能是内存越界导致的。
    用gdb单步跟踪一下吧,不然根本不知道蹦在哪里了。
    也可以设置一下,崩溃会产生coredump文件,然后用gdb跟踪,应该很容易就找出问题了。

    希望能够帮到你。

    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿