c9-10-1.c 808 B

12345678910111213141516171819
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #define LEN sizeof(struct student)
  4. struct student //声明结构体类型struct student
  5. {long num;
  6. float score;
  7. struct student *next;
  8. };
  9. int n; //全局变量n
  10. void print(struct student *head) //定义print函数
  11. {struct student *p; //在函数中定义struct student类型的变量p
  12. printf("\nNow,These %d records are:\n",n);
  13. p=head; //使p指向第一个结点
  14. if(head!=NULL) //若不是空表
  15. do
  16. {printf("%ld %5.1f\n",p->num,p->score); //输出一个结点中的学号与成绩
  17. p=p->next; //p指向下一个结点
  18. }while(p!=NULL); //当p不是“空地址”
  19. }