
C语言 用户自定数据类型的例题出错了,求帮忙看下哪错了
#include<stdio.h>#include<string.h>#defineLA3#defineLB4structstudent{intnum;charname[...
#include <stdio.h>
#include <string.h>
#define LA 3
#define LB 4
struct student
{
int num;
char name[8];
struct student *next;
} a[LA], b[LB];
int main()
{
struct student a[LA]= {{101,"wang"},{102,"LI"},{105,"zhang"}};
struct student b[LB]= {{103,"zhang"},{104,"ma"},{105,"chen"},{107,"guo"}};
int i;
struct student *p, *p1, *p2, *head1, *head2;
head1 = a;
head2 = b;
printf("list A: \n");
for (p1=head1,i=1; i<=LA; i++)
{
if(i<LA)
(*P1).next = a+i;
else
(*P1).next = NULL;
printf("%4d%8s\n",(*P1).num,(*P1).name);
if (i<LA)
p1 = (*P1).next;
}
printf("\n list B:\n");
for (p2=head2,i=1; i<=LB; i++)
{
if (i<LB)
(*P2).next = b + i;
else
(*P2).next = NULL;
printf("%4d%8s\n",(*P2).num,(*P2).name);
if (i<LB)
p2 = (*P2).next;
}
//对A表删除
p1 = head1;
while (p1!=NULL)
{
p2 = head2;
while (((*P1).num != (*P2).num) && ((*P2).next != NULL))
p2 = (*P2).next
if ((*P1).num == (*P2).num)
{
if (p1 == head1)
head1 = (*P1).next;
else {
(*P).next = (*P1).next;
p1 = (*P1).next;
}
}
else
{ p=p1; p1=(*P1).next;}
}
printf("\nresult:\n");
p1 = head1;
while(p1!=NULL)
{
printf("%4d %7s \n",(*P1).num,(*P1).name);
p1 = (*P1).next;
}
return 0;
} 展开
#include <string.h>
#define LA 3
#define LB 4
struct student
{
int num;
char name[8];
struct student *next;
} a[LA], b[LB];
int main()
{
struct student a[LA]= {{101,"wang"},{102,"LI"},{105,"zhang"}};
struct student b[LB]= {{103,"zhang"},{104,"ma"},{105,"chen"},{107,"guo"}};
int i;
struct student *p, *p1, *p2, *head1, *head2;
head1 = a;
head2 = b;
printf("list A: \n");
for (p1=head1,i=1; i<=LA; i++)
{
if(i<LA)
(*P1).next = a+i;
else
(*P1).next = NULL;
printf("%4d%8s\n",(*P1).num,(*P1).name);
if (i<LA)
p1 = (*P1).next;
}
printf("\n list B:\n");
for (p2=head2,i=1; i<=LB; i++)
{
if (i<LB)
(*P2).next = b + i;
else
(*P2).next = NULL;
printf("%4d%8s\n",(*P2).num,(*P2).name);
if (i<LB)
p2 = (*P2).next;
}
//对A表删除
p1 = head1;
while (p1!=NULL)
{
p2 = head2;
while (((*P1).num != (*P2).num) && ((*P2).next != NULL))
p2 = (*P2).next
if ((*P1).num == (*P2).num)
{
if (p1 == head1)
head1 = (*P1).next;
else {
(*P).next = (*P1).next;
p1 = (*P1).next;
}
}
else
{ p=p1; p1=(*P1).next;}
}
printf("\nresult:\n");
p1 = head1;
while(p1!=NULL)
{
printf("%4d %7s \n",(*P1).num,(*P1).name);
p1 = (*P1).next;
}
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询