#include <stdio.h>
#include <malloc.h>
//#define NULL 0
#define LEN sizeof(struct student)
struct student
{
long num;
float score;
struct student *next;
};
struct student * creat()
{
struct student *head = NULL;
struct student *p1,*p2;
int n=0;
p1=p2=(struct student*)malloc(LEN);
int numb = 0;
float scor = 0.0;
scanf(\"%d,%f\", &numb, &scor);
p1->num = numb;
p1->score = scor;
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\", &numb, &scor);
p1->num = numb;
p1->score = scor;
p1->next = NULL;
}
p2->next = p1;
return(head);
}
void output(struct student *head)
{
struct student *p1 = head;
while(p1!=NULL && p1->next!=NULL)
{
printf(\"%ld,%f\\n\", p1->num, p1->score);
p1 = p1->next;
}
printf(\"\\nIt\'s the end!\\n\");
}
int main(int argc,char** argv)
{
struct student *head = creat();
output(head);
return 0;
} |