C语言程序改错及填空题库
PAGE 1
gc23.c下列程序是建立一个包含学生有关数据的单向链表。但该程序有2个错误,错误出现在
每个注释行附近,请调试改正。调试改正中,不得改变程序结构,也不得增删语句。
#define NULL 0
struct stud
{
long num;
char name[10];
float score;
struct stud *next;
};
/* …………… comment …………… */
int n;
struct stud create() struct stud *create(void)
{
struct stud *head,*p1,*p2;
n=0;
p1=p2=(struct stud *)malloc(sizeof(struct stud));
scanf("%ld,%s,%f",&p1->num,p1->name,&p1->score);
/* ……………comment …………… */
head=NULL;
while(p1!=0) //while(p1->num!=0)
{
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p1=(struct stud *)malloc(size(struct stud));
scanf("%ld