0x00f03829 处未处理的异常: 0xC0000005: 读取位置 0x00000008 时发生访问冲突的问题是怎么回事
#include<stdio.h>#include <stdlib.h>
#define MAX_NODE_NUM 100
typedef struct nodetype
{
int id;
int cipher;
struct nodetype *next;
}node;
//isempty-----------------------------------------------
static int isempty(const node *phead)
{
if(phead=NULL)
{
printf("链表为空");
return 1;
}
else
return 0;
}
//getnode-----------------------------------------------
static node *getnode(const int iid,const int icipher)
{
node *p;
p=(node *)malloc(sizeof(node));
if(!p)
{
printf("memory is not enough");
exit(-1);
}
p->id=iid;
p->cipher=icipher;
p->next=NULL;
return p;
}
//createlist------------------------------------------------------
static void createlist(node**pphead,const int n)
{
int i,icipher;
node * pnew,*pcur;
pcur=(node *)malloc(sizeof(node));
for(i=1;i<=n;i++)
{
printf("输入第%d个人的密码",i);
scanf("%d",&icipher);
pnew=getnode(i,icipher);
if(*pphead=NULL)
{
*pphead=pcur=pnew;
pcur->next=*pphead;
}
else
{
pnew->next=pcur->next;
pcur->next=pnew;
pcur=pnew;
}
}
printf("完成单循环链表创建\n");
}
//statgame----------------------------------------------------------
static void statgame(node **pphead,int icipher)
{
int i,iflag=1;
node *pprv ,*pcur,*pdel;
pprv=pcur=*pphead;
while(pprv->next!=*pphead)
pprv=pprv->next;
while(iflag)
{
for(i=1;i<icipher;i++)
{
pprv=pcur;
pcur=pcur->next;
}
if(pprv==pcur)
iflag=0;
pdel=pcur;
pprv->next=pcur->next;
pcur=pcur->next;
icipher=pdel->cipher;
printf("第%d个人已出列,密码:%d\n",pdel->id,pdel->cipher);
free(pdel);
}
*pphead=NULL;
getchar();
}
//print--------------------------------------------------------------------
static void print( const node *phead)
{
const node *pcur=phead;
if(isempty(phead))
return ;
do
{
printf("第%d个人,密码:%d\n",pcur->id,pcur->cipher);
pcur=pcur->next;
}while(pcur!=phead);
getchar();
}
int main()
{
int n,m;
node *phead;
phead=(node *)malloc(sizeof(node));
phead=NULL;
while(1)
{
printf("请输入人数n(最多%d)",MAX_NODE_NUM);
scanf("%d",&n);
printf("和初始密码m:");
scanf("%d",&m);
if(n>MAX_NODE_NUM)
{
printf("输入的人数太多");
continue;
}
else break;
}
createlist(&phead,n);
printf("\n链表原始情况打印:\n");
//print(phead);
printf("\n链表删除情况打印:\n");
statgame(&phead,m);
system("pause");
return 0;
}
红色字体部分:0x00f03829 处未处理的异常: 0xC0000005: 读取位置 0x00000008 时发生访问冲突