这个代码虽然没问题,但是第二次输入的数据就会覆盖之前的那一个,但是我想将他们连接在一起,
就是两个一起输出而不是覆盖
我该怎么改呢
就是第一次全输入1,然后打印,然后选“y”
然后全输入2,这样第二次只会全部打印2,但是我想11111111和22222222都有
#include<stdio.h>
#include<stdlib.h>
struct course *head1;
struct course
{
int bianhao;//编号
char mingcheng[20];// 名称
char xingzhi[20];//性质
int xueshi;//学时
int xueqi;//学期
int zongrenshu;//总人数
int yixuanrenshu; //已选人数
char jiaoshi[20];
char leixing[20];
struct course * next;
};
int main()
{
start:;
int a;
struct course *p,*p1;
p=(struct course*)malloc(sizeof(struct course));
printf("课程性质中,分为文科类和理科类\n类型中,分为必修、限选、实践、实习\n");
printf("课程编号\t课程名称\t课程性质\t学时\t学期\t可选人数\t主讲教师\t类型\t\n");
scanf("%d %s %s %d %d %d %s %s",&p->bianhao,p->mingcheng,p->xingzhi,&p->xueshi,&p->xueqi,&p->zongrenshu,p->jiaoshi,p->leixing);
p->yixuanrenshu=0;
p->next=NULL;
head1=p;
printf("是否继续录入?1代表yes,2代表no\n");
scanf("%d",&a);
switch(a)
{
case 1:
{
do
{
p1=(struct course*)malloc(sizeof(struct course));
p->next=p1;
printf("请输入\n");
scanf("%d %s %s %d %d %d %s %s",&p1->bianhao,p1->mingcheng,p1->xingzhi,&p1->xueshi,&p1->xueqi,&p1->zongrenshu,p1->jiaoshi,p1->leixing);
p1->next=NULL;
p1->yixuanrenshu=0;
printf("是否继续录入?1代表yes,2代表no\n");
scanf("%d",&a);
// p=p->next;
}
while(a==1);
break;
}
case 2:
break;
default:
break;
}
printf("编号\t名称\t性质\t学时\t学期\t已选\t总人数\t教师\t类型\n");
while(p!=NULL)
{
printf("%d\t%s\t%s\t%d\t%d\t%d\t%d\t%s\t%s\n",p->bianhao,p->mingcheng,p->xingzhi,p->xueshi,p->xueqi,p->yixuanrenshu,p->zongrenshu,p->jiaoshi,p->leixing);
p=p->next;
}
printf("是否继续输入?y or n");
char c;
scanf("%s",&c);
if (c=='y');
goto start;
}