1
0

c9-10-2.c 867 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #define LEN sizeof(struct student)
  4. struct student
  5. {long num;
  6. float score; struct student *next;
  7. };
  8. int n;
  9. struct student *creat()
  10. {struct student *head;
  11. struct student *p1,*p2;
  12. n=0;
  13. p1=p2=( struct student*) malloc(LEN);
  14. scanf("%ld,%f",&p1->num,&p1->score);
  15. head=NULL;
  16. while(p1->num!=0)
  17. {n=n+1;
  18. if(n==1)head=p1;
  19. else p2->next=p1;
  20. p2=p1;
  21. p1=(struct student*)malloc(LEN);
  22. scanf("%ld,%f",&p1->num,&p1->score);
  23. }
  24. p2->next=NULL;
  25. return(head);
  26. }
  27. void print(struct student *head)
  28. {struct student *p;
  29. printf("\nNow,These %d records are:\n",n);
  30. p=head;
  31. if(head!=NULL)
  32. do
  33. {printf("%ld %5.1f\n",p->num,p->score);
  34. p=p->next;
  35. }while(p!=NULL);
  36. }
  37. int main()
  38. {struct student *head ;
  39. head=creat();
  40. print(head);
  41. return 0;
  42. }