我编了个关于链表操作的程序,但程序分别在turbo c和vc++里面运行时出现了不同的情况:turbo c里面运行正常,但vc++里面却有个warning:"exe' has exited with code -1073741510 (0xC000013A),no matching symbolic information found."每次程序运行到往结点p里输入数字时,就不在往下运行了.
哪位仁兄能解释一下
谢了
错误在main函数里,struct node *p的问题
# include <stdio.h>
# include <malloc.h>
# define NULL 0
# define LEN sizeof(struct node)
struct node{
int data;
struct node *next;
};
struct node * Init_list(void)
{
struct node *head;
head=(struct node *)malloc(LEN);
if(head)
{
head->next=NULL;
}
return (head);
}
struct node * create_list(int n)
{
int i;
struct node *p1,*p2,*p3;
p3=p2=p1=(struct node *)malloc(LEN);
for(i=0;i<n;i++)
{
p1=(struct node *)malloc(LEN);
p2->next=p1;
p2=p1;
}
p2->next=NULL;
return(p3);
}
void input(struct node * head)
{
struct node *p1;
p1=head->next;
while(p1)
{
scanf("%d",&p1->data);
p1=p1->next;
}
}
void output(struct node *head)
{
struct node *p2;
p2=head->next;
while(p2)
{
printf("%d ",p2->data);
p2=p2->next;
}
}
void insert_list(int n,int *m,struct node *head)
{
int i;
struct node *p;
struct node *q;
p=head->next;
q=(struct node *)malloc(LEN);
printf("Please input the data in node q;\n");
scanf("%d",&q->data);
if(n>m)
{
printf("fail to insert\n");
}
for(i=1;i<=m;i++)
{
if(i!=n)
{
p=p->next;
}
else
{
q->next=p->next;
p->next=q;
*m+=1;
printf("Success.\n");
}
}
}
void delete_list(int n,int *m,struct node * head)
{
int i;
struct node *p1,*p2;
p1=head->next;
p2=head;
if(n>m)
{
printf("fail to detele.\n");
}
for(i=1;i<=m;i++)
{
if(i!=n)
{
p2=p1;
p1=p1->next;
}
else
{
p2->next=p1->next;
p1->next=NULL;
*m-=1;
printf("Success.\n");
printf("delete %d\n",p1->data);
free(p1);
}
}
}
void main()
{
struct node *p,*q;
struct node *head;
int seat1,seat2;
int len;
int *len_ptr;
printf("\nPlease input the length of the list:\n");
scanf("%d",&len);
len_ptr=&len;
head=Init_list();
head->next=create_list(len);
printf("\nNow,you will input the numbers into the list.\n");
input(head);
printf("\nNow,please check these data.\n");
output(head);
printf("\n");
printf("\nlength is %d\n",*len_ptr);
printf("\nplease input the data in node p:\n");
scanf("%d",&p->data);
p->next=head->next;
head->next=p;
*len_ptr+=1;
output(head);
printf("\nlength is %d\n",*len_ptr);
printf("\n");
printf("\nNow,please locate the inserted seat.\n");
scanf("%d",&seat1);
insert_list(seat1,len_ptr,head);
output(head);
printf("\n");
printf("\nlength is %d\n",*len_ptr);
printf("\nNow,please locate the deleted seat.\n");
scanf("%d",&seat2);
delete_list(seat2,len_ptr,head);
output(head);
printf("\n");
printf("\nlength is %d\n",*len_ptr);
}