#include <stdio.h> #include <malloc.h> struct student { int num; int score; struct student *next; }; int n; struct student *creat(void) { struct student *head; struct student *p1,*p2; n=0; p1=p2=(struct student *)malloc(sizeof(struct student)); scanf("%d %d",&p1->num,&p1->score); head=NULL; while(p1->num!=0) { n=n+1; if(n==0) head=p1; else p2->next=p1; p2=p1; p1=(struct student *)malloc(sizeof(struct student)); scanf("%d %d",&p1->num,&p1->score); } p2->next=NULL; return(head); } void print(struct student *head) { struct student *p; printf("这%d个记录为:/n",n); p=head; if(head!=NULL) do { printf("%d %d",p->num,p->score); p=p->next; } while(p!=NULL); } int main() { struct student *head; printf("请输入NUM 以及 SCORE:/n"); head=creat(); print(head); system("pause"); }