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

一元多项式计算.exe 中的 0x0041e60d 处未处理的错误: 0xC0000005: 读取位置 0x00000004 时发生访问冲突

2012-02-10 
一元多项式计算.exe 中的 0x0041e60d 处未处理的异常: 0xC0000005: 读取位置 0x00000004 时发生访问冲突 。

一元多项式计算.exe 中的 0x0041e60d 处未处理的异常: 0xC0000005: 读取位置 0x00000004 时发生访问冲突 。
本人写了一个C++小程序,一元多项式的计算,但是执行时出现上面的错误,哪位大侠帮我改改啊,谢谢!代码如下:
#include <iostream>
using   namespace   std;

typedef   struct   ElemType  
{
float   coef;//系数
int   expn;//指数
}ElemType;

typedef   struct   node
{
ElemType   data;
struct   node   *next;
}node,*polynomial;

void   Initpoly(polynomial   &p)
{
p=new   node;
p-> data.coef=0.0;
p-> data.expn=0;
p-> next=NULL;
}

int   cmp(ElemType   a1,ElemType   a2)
{
if(a1.expn> a2.expn)return   1;
if(a1.expn <a2.expn)return   -1;
else   return   0;
}

void   Insertpoly(polynomial   p1,ElemType   e)
{
polynomial   p,pnew;
p=p1;
pnew=new   node;
while(p-> next!=NULL)
{
if(cmp(p-> next-> data,e)==-1)p=p-> next;
else   break;

}
pnew-> data=e;
pnew-> next=NULL;

if(cmp(p-> next-> data,e)==0)p-> data.coef+=e.coef;//出错的行
else
{
pnew-> next=p-> next;p-> next=pnew;
}

}

void   Creatpoly(polynomial   &poly)
{
int   i=1;
ElemType   e;
cout < < "请输入第 " < <i < < "个多项式的系数和指数 " < <endl;
cin> > e.coef;
cin> > e.expn;

Initpoly(poly);
while(e.coef!=0||e.expn!=0)
{
Insertpoly(poly,e);
cin> > e.coef> > e.expn;
}
i++;

}

void   Appendpoly(polynomial   &p1,polynomial   &p2)
{
polynomial   p;
p=p1;
while(p-> next!=NULL)
{
p=p-> next;
p-> next=p2;
}
}

void   Addpoly(polynomial   p1,polynomial   p2)
{
polynomial   h1,h2;
h1=p1-> next;
h2=p2-> next;
while(h1!=NULL&&h2!=NULL)
{
switch(cmp(h1-> data,h2-> data))
{
case   1:{
Insertpoly(p1,h2-> data);
h2=h2-> next;
break;
      }
case   0:{
h1-> data.coef+=h2-> data.coef;
h1=h1-> next;
h2=h2-> next;
break;
      }
case   -1:{
Insertpoly(h1,h2-> data);
h2=h2-> next;
h1=h1-> next;
break;
}
}
}
if(h2!=NULL)Appendpoly(p1,h2);
cout < < "两个多项式的和是: ";
}

void   Destroypoly(polynomial   p)
{
while(p!=NULL)
{
polynomial   p1=p;
p=p-> next;
free(p1);
}
}

void   Printpoly(polynomial   p)
{
polynomial   p1=p-> next;
cout < <p1-> data.coef < <p1-> data.expn;
p1=p1-> next;
while(p1!=NULL)
{
cout < <p1-> data.coef < <p1-> data.expn;
p1=p1-> next;

}
cout < <endl;
}

void   main()
{
polynomial   p1;
Creatpoly(p1);
Printpoly(p1);

polynomial   p2;
Creatpoly(p2);
Printpoly(p2);
Addpoly(p1,p2);
Printpoly(p1);
Destroypoly(p2);
Destroypoly(p1);
}


“一元多项式计算.exe”:   已加载“G:\本学期课程\课程设计\一元多项式计算\Debug\一元多项式计算.exe”,已加载符号。
“一元多项式计算.exe”:   已加载“C:\WINDOWS\system32\ntdll.dll”,未加载任何符号。


“一元多项式计算.exe”:   已加载“C:\WINDOWS\system32\kernel32.dll”,未加载任何符号。
一元多项式计算.exe   中的   0x0041e60d   处最可能的异常:   0xC0000005:   读取位置   0x00000004   时发生访问冲突   。
一元多项式计算.exe   中的   0x0041e60d   处未处理的异常:   0xC0000005:   读取位置   0x00000004   时发生访问冲突   。
程序“[3192]   一元多项式计算.exe:   本机”已退出,返回值为   0   (0x0)。

[解决办法]
访问空指针了
[解决办法]
就不能把程序写成 C++ 风格的?……
[解决办法]
若在多线程中出现这样的错误的话,就是你的指针所指向的内容在一个线程里写的同时,可在另一个线程里读的话就会报这样的错

热点排行