问题遇到的现象和发生背景
输出一行的时候没问题,输出两三行就有乱码,这怎么解决
问题相关代码,请勿粘贴截图
#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(){
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,&p->jiaoshi,&p->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;
}
struct course *c;
c=(struct course*)malloc(sizeof(struct course));
c=head1; printf("编号\t名称\t性质\t学时\t学期\t已选\t总人数\t教师\t类型\n");
if(c->next==NULL){
printf("%d\t%s\t%s\t%d\t%d\t%d\t%d\t%s\t%s\n",c->bianhao,c->mingcheng,c->xingzhi,c->xueshi,c->xueqi,c->yixuanrenshu,c->zongrenshu,c->jiaoshi,c->leixing);
goto end1;}
while(c->next!=NULL){
printf("%d\t%s\t%s\t%d\t%d\t%d\t%d\t%s\t%s\n",c->bianhao,c->mingcheng,c->xingzhi,c->xueshi,c->xueqi,c->yixuanrenshu,c->zongrenshu,c->jiaoshi,c->leixing);
c=c->next;
}
if(c->next==NULL)
printf("%d\t%s\t%s\t%d\t%d\t%d\t%d\t%s\t%s\n",c->bianhao,c->mingcheng,c->xingzhi,c->xueshi,c->xueqi,c->yixuanrenshu,c->zongrenshu,c->jiaoshi,c->leixing);
end1:;
}