#include<stdio.h>
#include<stdlib.h>
struct togglep
{
int value;
struct togglep *nextp;
}*abc[5];
void printp(struct togglep *p)
{
while(!(p==NULL))
{
printf("%4d",p->value);
p=p->nextp;//出错的行
}
}
main ()
{
struct togglep *p,*p1;
int i;
//造出一个指针链
p=(struct togglep *)malloc(sizeof(struct togglep *));
if (p==NULL)
printf("malloc is error");
scanf("%d",&p->value);
p1=p;
p=p->nextp;
for(i=1;i<5;i++)
{
p=(struct togglep *)malloc(sizeof(struct togglep *));
abc[i]=p;
if(p==NULL)
{
printf("malloc is error");
exit(0);
}
scanf("%d",&p->value);
p=p->nextp;
}
p=NULL;
printp(p1);
return 0;
}
不行为什么,运行到//出错的行 位置时,就跳出如图窗口然后强制退出了。和编译器有关吗?我用的是VC++6.0,还是我逻辑错误?
#include<stdlib.h>
struct togglep
{
int value;
struct togglep *nextp;
}*abc[5];
void printp(struct togglep *p)
{
while(!(p==NULL))
{
printf("%4d",p->value);
p=p->nextp;//出错的行
}
}
main ()
{
struct togglep *p,*p1;
int i;
//造出一个指针链
p=(struct togglep *)malloc(sizeof(struct togglep *));
if (p==NULL)
printf("malloc is error");
scanf("%d",&p->value);
p1=p;
p=p->nextp;
for(i=1;i<5;i++)
{
p=(struct togglep *)malloc(sizeof(struct togglep *));
abc[i]=p;
if(p==NULL)
{
printf("malloc is error");
exit(0);
}
scanf("%d",&p->value);
p=p->nextp;
}
p=NULL;
printp(p1);
return 0;
}
不行为什么,运行到//出错的行 位置时,就跳出如图窗口然后强制退出了。和编译器有关吗?我用的是VC++6.0,还是我逻辑错误?