以解决了。。不过还是留着吧,给和我一样的新手参考一下,稍微改了一下
#include<stdio.h>#include<malloc.h>
#define len sizeof(struct student)
struct student
{ long num;
float score;
struct student *next;
};
struct student *creat(void)
{ struct student *p1,*p2,*head;
int n=0;
p1=p2=(struct student *)malloc(len);
printf("请输入学号和成绩(格式为:学号,成绩。输入0则结束):\n");
scanf("%ld,%f",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0)
{ n++;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(len);
scanf("%ld,%f",&p1->num,&p1->score);
}
p2->next=NULL;
return(head);
}
void output(struct student *head)
{
struct student *p;
p=head;
if(head!=NULL)
printf("输出成绩:\n");
do
{ printf("%ld %.0f\n",p->num,p->score);
p=p->next;
}while(p!=NULL);
}
struct student *shan(struct student *head,long x)
{
struct student *p1,*p2;
p1=head;
while(x!=p1->num&&p1->next!=NULL)
{ p2=p1;p1=p1->next;}
p2->next=p1->next;
printf("%ld\n",x);
return(head);
}
void main()
{ long x;
struct student *p,*head;
head=creat();
p=head;
output(p);
printf("请输入要删除学生的学号:");
scanf("%ld",&x);
p=(struct student *)shan(p,x);
output(p);
}
[ 本帖最后由 xdh0817 于 2011-11-13 00:27 编辑 ]