关于列表问题!谢谢
谢谢大家能看我的帖:问题如下:能编译出来,但是输入不了!不知道哪里出问题了,大家给看看!
#include"stdio.h"
#include"malloc.h"
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
int xuehao;
char xingming[10];
int yuwen;
int shuxue;
int yingyu;
int wuli;
int huaxue;
int zhengzhi;
int dili;
int lishi;
int shengwu;
struct student *next;
};
int n;
struct student *creat(void)
{
struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(LEN); //*开辟一个新单元*//
scanf("%ld,%s,%d,%d,%d,%d,%d,%d,%d,%d,%d",&p1->xuehao,&p1->xingming,&p1->yuwen,&p1->shuxue,&p1->yingyu,&p1->wuli,&p1->huaxue,&p1->zhengzhi,&p1->dili,&p1->lishi,&p1->shengwu);
head=NULL;
while(&p1->xuehao!=0)
{
n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
scanf("%ld,%s,%d,%d,%d,%d,%d,%d,%d,%d,%d",&p1->xuehao,&p1->xingming,&p1->yuwen,&p1->shuxue,&p1->yingyu,&p1->wuli,&p1->huaxue,&p1->zhengzhi,&p1->dili,&p1->lishi,&p1->shengwu);
}
p2->next=NULL;
return(head);
}
void print(struct student *head)
{
struct student *p;
printf("adfadf%d\n",n);
p=head;
if(head!=NULL)
do
{
printf("%ld,%s,%d,%d,%d,%d,%d,%d,%d,%d,%d",p->xuehao,p->xingming,p->yuwen,p->shuxue,p->yingyu,p->wuli,p->huaxue,p->zhengzhi,p->dili,p->lishi,p->shengwu);
p=p->next;
}while(p!=NULL);
}
void main()
{
struct student *head,stu;
long del_num;
printf("建立\n");
head=creat();
print(head);
}