#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct Student)
struct Student
{
int num;
float score;
struct Student *next;
};
int n;
struct Student *creat(void)
{
struct Student *head,*p1,*p2;
p1=p2=(struct Student *)malloc(LEN);
n=0;
scanf("%d,%f",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0);
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct Student *)malloc(LEN);
scanf("%d,%f",&p1->num,&p1->score);
}
p2->next=NULL;
return(head);
}
int main()
{
struct Student *p;
p=creat();
do
{
printf("%d,%f\n",p->num,p->score);
p=p->next;
}while(p->next!=NULL);
return 0;
}
以上,没有语法错误
但是出现输入第一次数据后就不能再输数据的问题
求教!!!
#include<stdlib.h>
#define LEN sizeof(struct Student)
struct Student
{
int num;
float score;
struct Student *next;
};
int n;
struct Student *creat(void)
{
struct Student *head,*p1,*p2;
p1=p2=(struct Student *)malloc(LEN);
n=0;
scanf("%d,%f",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0);
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct Student *)malloc(LEN);
scanf("%d,%f",&p1->num,&p1->score);
}
p2->next=NULL;
return(head);
}
int main()
{
struct Student *p;
p=creat();
do
{
printf("%d,%f\n",p->num,p->score);
p=p->next;
}while(p->next!=NULL);
return 0;
}
以上,没有语法错误
但是出现输入第一次数据后就不能再输数据的问题
求教!!!