这是部分程序:
struct student *initlist(){
struct student* head;
struct student* p,*q;
int n,i;
p=( struct student* )malloc(sizeof(struct student));
head=q=p;
p->next=NULL;
if(!p){ exit(0);}
printf("输入学生人数n=");
scanf("%d",&n);
if(n==0){exit(0);}
for(i=1;i<=n;i++){
printf("\t请输入第%d个学生信息:\n",i);
p=( struct student*)malloc(sizeof( struct student));
if(!p){ exit(0);}
p->avg=0;
printf("--------------------------------------------------\n");
printf("\t请你输入姓名:");
scanf("%s",&p->name);
printf("\t请你输入学号:");
scanf("%d",&p->num);
printf("\t请你输入数学成绩:");
scanf("%d",&p->math);
printf("\t请你输入英语成绩:");
scanf("%d",&p->english);
printf("\t请你输入C语言成绩:");
scanf("%d",&p->c);
p->avg=((p->math)+(p->english)+(p->c))/3;
printf("--------------------------------------------------\n");
if(i==0){break;}
else{
q->next=p;
q=p;
p->next=NULL;
}
}
return(head);
}
struct student* del(struct student *head){ //删除
struct student *p,*q;
int num;
printf("请输入删除学生的学号:");
scanf("%d",&num);
if(head==NULL){printf("\n没有记录!\n"); goto end;}
p=head;
while(p->num!=num&&p->next!=NULL){//运行到这有错
q=p;
p=p->next;
}
if(p->num==num)
{
if(p==head) head=p->next;
else q->next=p->next;
printf("记录已经被删除!\n");
free(p);
}
end: return(head);
}
编译时没有错,可是运行红色处时有错为了expression cannot be evaluated
这是为什么????????