现在的位置: 首页 > 综合 > 正文

unhandled exception in .exe :0xC0000005:Access Violation.

2013年06月18日 ⁄ 综合 ⁄ 共 1365字 ⁄ 字号 评论关闭

 各位高手帮帮忙,我是大一的初学者~

最近用C++写了一个程序,可是程序有点问题,编译通过,运行exe文件时,选第一个功能时会出现unhandled exception in .exe :0xC0000005:Access Violation.的错误。通过网上查资料可以肯定是指针问题,可是还是搞不懂是那个指针没有传出值来。不知道怎么改~请各路高手来指导一下,感激不尽~~~

现在把相关的代码贴一下~
struct toupiao * creat(struct toupiao *t)
{
struct toupiao *p1=t,*p2;
struct xuanxiang *head1,*b1,*b2;
int i=1;

if((p2=(struct toupiao *)malloc(LEN))==NULL)
{
printf("内存不足!/n");
exit(0);
}
scanf("%s",p2->tm);
if((head1=(struct xuanxiang *)malloc(LON))==NULL)
{
printf("内存不足!/n");
exit(0);
}
b1=head1;
b1->vot=0;

printf(" %d. ",i);
scanf("%s",b1->xm);
b1->vot=0;
for(i=2;strcmp(b1->xm,"OK")!=0;i++)
{
printf("/n");
if((b2=(struct xuanxiang *)malloc(LON))==NULL)
{
printf("内存不足!/n");
exit(0);
}
b2->vot=0;
printf(" %d. ",i);
scanf("%s",b2->xm);
b1->next=b2;
b1=b2;
}
b1->next=NULL;
p2->xx=head1;
p2->next=NULL;
p1->next=p2;
return p2;
}
void main()
{
int a;
struct toupiao *p=NULL,*head;
struct toupiao * creat(struct toupiao *t);
void check(struct toupiao*l);
system("cls");
if((head=(struct toupiao *)malloc(LEN))==NULL)
{
printf("内存不足!/n");
exit(0);
}
head->next=NULL;
scanf("%d",&a);
switch(a)
{
case 1:
system("cls");
if(head->next=NULL)
p=creat(head);
else
p=creat(p);
printf("/n");
break;
case 2:
system("cls");
check(head);
break;
case 3:
system("cls");
printf("*************** 谢 ***** 谢 ***** 使 ***** 用 ******************/n");
getchar();
exit(0);
default:
system("cls");
printf

printf("*************** 请 选 择 正 确 的 功 能 序 号 ******************/n");
getchar();
}
}

 

调试时,指示错误的箭头指向creat函数里的倒数第二句p1->next=p2;

 

抱歉!评论已关闭.