求救啊 编译连接没错 但运行出现错误 unhandled exception in xxxexe 0xC0000005:Access..

_Natsu 2010-04-22 11:57:01
#include "stdio.h"
#include "stdlib.h"
typedef char Datament;
struct data
{
Datament Data;
data *next;
};
typedef data Nodes,*Node;
struct S
{
data * pos;
int snum;
};
typedef S stacks,*Stacks;
struct Q
{
int qnum;
data* first;
data* tear;
};
typedef struct Q queues,*Queues;
Stacks Screat(void);
bool SEmpty(Stacks Stack);
void push(Stacks &Stack,Datament e);
Datament pop(Stacks &Stack);
int SLength(Stacks Stack);
Datament SGetTop(Stacks Stack);
void ClearStack(Stacks &Stack);
void SAllout(Stacks Stack);
void SFormatOut(Stacks &Stack);
void SDestroy(Stacks &Stack);
//void Stackvisit(Stacks Stack,(void *)visit()){}
Queues Qcreat(void);
bool QEmpty(Queues Queue);
void InQueue(Queues &Queue,Datament e);
Datament OutQueue(Queues &Queue);
int QLength(Queues Queue);
Datament GetFirst(Queues Queue);
Datament GetTear(Queues Queue);
void ClearQueue(Queues &Queue);
void QAllout(Queues Queue);
void QFormatOut(Queues &Queue);
void QDestroy(Queues &Queue);
int main(int argc, char *argv[])
{
Stacks Stack[100];
int i=0;
Queues Queue[100];
int j=0;
char buff[100];
buff[1]='\0';
int n;
int flag1=0;
int flag2=0;
while(flag1==0)
{
if(flag2==0)
{
printf(" 堆栈队列的应用 \n");
printf(" ======================================================\n");
printf(" 1.堆栈的建立.................................\n");
printf(" 2.堆栈的输出.................................\n");
printf(" 3.队列的建立.................................\n");
printf(" 4.队列的输出.................................\n");
printf(" 5.输入算术表达式....(前提是要有队列和堆栈哦!)\n");
printf(" 6.后序输入算术表达式(前提是要有队列和堆栈哦!)\n");
printf(" 7.输出算术表达式的值(前提是要有队列和堆栈哦!)\n");
printf(" 8.堆栈的销毁........(前提是要有队列和堆栈哦!)\n");
printf(" 9.队列的销毁........(前提是要有队列和堆栈哦!)\n");
printf(" 0.退出\n");
printf("=======================================================\n");
printf("请输入选择:(0-9)\n");
scanf("%s",buff);
}
flag2=0;
if((buff[0]>'9'||buff[0]<'0')||buff[1]!='\0')
n=10;
else
{
n=int(buff[0]-0x30);
}
switch(n)
{
case 1:
if(i>=100)
{
printf("已达到最大容量!Please Destroy some Stacks~!\n");
}
else
{
Stack[i]=Screat();
i++;
printf("操作完成!prefect!\n");
printf("您已经建立了%d个堆栈\n",i);
printf("Please In put the number!(Press the ENTER to stop!)\n");
printf("InPut:\t");
Datament Buff[100];
scanf("%s",Buff);
int count=0;
while(Buff[count]!='\0')
{
push(Stack[i],Buff[count]);
count++;
}
}
break;
case 2:
if(i==0)
printf("No Stacks in it!Please build one!\n");
else
SAllout(Stack[i]);
break;
case 3:
if(j>=100)
printf("已达到最大容量!Please Destroy some Queues~!\n");
else
{
Queue[j]=Qcreat();
j++;
printf("操作完成!prefect!\n");
printf("您已经建立了%d个队列!\n",j);
printf("Please In put the number!(Press the ENTER to stop!)\n");
printf("InPut:\t");
Datament Buff[100];
scanf("%s",Buff);
int count=0;
while(Buff[count]!='\0')
{
InQueue(Queue[j],Buff[count]);
count++;
}
}
break;
case 4:
if(j==0)
printf("No Stacks in it!Please build one!\n");
else
QAllout(Queue[j]);
break;
case 5:
char Exp[100];
printf("Please enter the expression!\n");
scanf("%s",Exp);
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 10:
printf("操作有误哦!please try again!:");
scanf("%s",buff);
flag2=1;
break;
case 0:
flag1=1;
break;
default:
exit(0);
break;
}
if(flag1!=0)
printf("退出!\n");
else
{
if(flag2==0)
{
printf("请继续选择下面选项!(任意键返回!)\n",i);
system("pause");
system("cls");
}
}
}
return 0;
}
Stacks Screat(void)
{
Stacks Stack=new stacks;
if(Stack==NULL)
{
printf("Memory Less!\n");
exit(-2);
}
else
{
Stack->pos=(Node)malloc(sizeof(Nodes));
Stack->snum=0;
return Stack;
}
}
bool SEmpty(Stacks Stack)
{
return Stack->snum==0;
}
void push(Stacks &Stack,Datament e)
{
Node p=(Node)malloc(sizeof(Nodes));
if(p==NULL)
{
printf("Memory Less!\n");
exit(-2);
}
p->Data=e;
p->next=Stack->pos;
Stack->pos=p;
Stack->snum++;
}
Datament pop(Stacks &Stack)
{
Datament e;
Node p;
if(SEmpty(Stack)==1)
{
printf("The empty Stack!\n");
return 0;
}
else
{
p=Stack->pos;
Stack->pos=p->next;
Stack->snum--;
e=p->Data;
delete p;
return e;
}
}
int SLength(Stacks Stack)
{
return Stack->snum;
}
Datament SGetTop(Stacks Stack)
{
Datament e;
if(SEmpty(Stack)==1)
{
printf("The Empty Stack!\n");
return 0;
}
e=Stack->pos->Data;
return e;
}
void ClearStack(Stacks &Stack)
{
Node p;
while(Stack->pos!=NULL)
{
p=Stack->pos;
Stack->pos=p->next;
free(p);
}
Stack->snum=0;
}
void SAllout(Stacks Stack)
{
Node p;
Datament e;
if(SEmpty(Stack)==1)
{
printf("The empty Stack!\n");
return;
}
else
{
p=Stack->pos;
while(p!=NULL)
{

e=p->Data;
p=p->next;
printf("%2M",e);
}
printf("\n");
}
}
void SFormatOut(Stacks &Stack)
{
SAllout(Stack);
ClearStack(Stack);
}
void SDestroy(Stacks &Stack)
{
Node p=NULL;
while(Stack->pos!=NULL)
{
p=Stack->pos;
Stack->pos=p->next;
free(p);
}
delete Stack;
}
//void Stackvisit(Stacks Stack,(void *)visit()){}
Queues Qcreat(void)
{
Queues Queue=new queues;
if(Queue==NULL)
{
printf("Memory Less!\n");
exit(-2);
}
Node p=(Node)malloc(sizeof(Nodes));
Queue->qnum=0;
Queue->first=p;
Queue->tear=NULL;
Queue->first->next=Queue->tear;
Queue->first->Data='\0';
return Queue;
}
bool QEmpty(Queues Queue)
{
return Queue->qnum==0;
}
void InQueue(Queues &Queue,Datament e)
{
Node p=(Node)malloc(sizeof(Nodes));
if(p==NULL)
{
printf("Memory Less!\n");
exit(-2);
}
p->Data=e;
Queue->tear->next=p;
Queue->tear=p;
Queue->tear->next=NULL;
Queue->qnum++;
}
Datament OutQueue(Queues &Queue)
{
Datament e;
Node p;
if(QEmpty(Queue)==1)
{
printf("The empty Queue!\n");
return 0;
}
else
{
p=Queue->first;
Queue->first=p->next;
Queue->qnum--;
e=Queue->first->Data;
free(p);
return e;
}
}
int QLength(Queues Queue)
{
return Queue->qnum;
}
Datament GetFirst(Queues Queue)
{
if(QEmpty(Queue)==1)
{
printf("The Empty Queue!\n");
return 0;
}
return Queue->first->next->Data;
}
Datament GetTear(Queues Queue)
{
if(QEmpty(Queue)==1)
{
printf("The Empty Queue!\n");
return 0;
}
return Queue->tear->Data;
}
void ClearQueue(Queues &Queue)
{
Node p;
while(Queue->first->next!=NULL)
{
p=Queue->first;
Queue->first=p->next;
free(p);
}
Queue->qnum=0;
}
void QAllout(Queues Queue)
{
Node p;
Datament e;
if(QEmpty(Queue)==1)
{
printf("The empty Queue!\n");
return;
}
p=Queue->first;
while(p->next!=NULL)
{
p=p->next;
e=p->Data;
printf("%2M",e);
}
printf("\n");
}
void QFormatOut(Queues &Queue)
{
QAllout(Queue);
ClearQueue(Queue);
}
void QDestroy(Queues &Queue)
{
Node p;
while(Queue->first->next!=NULL)
{
p=Queue->first;
Queue->first=p->next;
free(p);
}
free(Queue->first);
free(Queue);
}
大牛们 救命啊 我调试了一8个小时了 求救啊!!!
...全文
128 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
_Natsu 2010-04-24
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 skyworth98 的回复:]
你只初始化的stack[i],却使用stack[i+1]……


C/C++ code

Stack[i]=Screat(); // 初始化Stack[i]
i++;
printf("操作完成!prefect!\n");
printf("您已经建立了%d个……
[/Quote]
谢谢了 漏洞百出了 主要是指针初始化方面出的问题 非常感谢~!已经知道怎么去改了 小菜我在这谢过大家了
_Natsu 2010-04-23
  • 打赏
  • 举报
回复
我都试过了 就算是全部初始化了 还是这样
azurezk 2010-04-23
  • 打赏
  • 举报
回复
指针都初始化了吗,没初始化不能用
ForestDB 2010-04-23
  • 打赏
  • 举报
回复
帮顶。
skyworth98 2010-04-23
  • 打赏
  • 举报
回复
你只初始化的stack[i],却使用stack[i+1]……


Stack[i]=Screat(); // 初始化Stack[i]
i++;
printf("操作完成!prefect!\n");
printf("您已经建立了%d个堆栈\n",i);
printf("Please In put the number!(Press the ENTER to stop!)\n");
printf("InPut:\t");
Datament Buff[100];
scanf("%s",Buff);
int count=0;
while(Buff[count]!='\0')
{
push(Stack[i],Buff[count]); // Push Stack[i+1]
count++;
}
「已注销」 2010-04-23
  • 打赏
  • 举报
回复
单步调试,看是哪一句有问题
skyworth98 2010-04-23
  • 打赏
  • 举报
回复
干什么的时候出错了??
向立天 2010-04-23
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 youfeng243 的回复:]
引用 3 楼 crystal28 的回复:
单步调试,看是哪一句有问题

基本上是同一个地方
[/Quote]

哪个地方?
_Natsu 2010-04-23
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 crystal28 的回复:]
单步调试,看是哪一句有问题
[/Quote]
基本上是同一个地方

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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