|  | 
 
 
 楼主|
发表于 2020-2-12 17:39:58
|
显示全部楼层 
| 前面是特别简单代码感觉没错啊
 #include <stdio.h>
 #include <malloc.h>
 
 #define LEN sizeof(struct student);
 
 int n;
 
 struct student
 {
 int num;
 int score;
 struct student *next;
 };
 
 struct student *creat();
 void print(struct student *head);
 
 void main()
 {
 
 struct student *stu;
 
 stu = creat();
 print(stu);
 
 printf("\n\n");
 }
 struct student *creat()
 {
 struct student *head;
 struct student *p1 , *p2;
 
 p1 = p2 = (struct student *)malloc(LEN);
 
 printf("Please enter the num :\n");
 scanf("%d",&p1->num);
 printf("Please enter the score :\n");
 scanf("%d",&p1->score);
 
 head = NULL;
 n = 0;
 
 while(p1->num != 0)
 {
 n++;
 if(n == 1)
 {
 head = p1;
 }
 else
 {
 p2->next = p1;
 }
 
 p2 = p1;
 p1 = (struct student *)malloc(LEN);
 
 printf("\nPlease enter the num :\n");
 scanf("%d",&p1->num);
 printf("Please enter the score :\n");
 scanf("%d",&p1->score);
 }
 p2->next = NULL;
 return (head);
 }
 
 void print(struct student *head)
 {
 struct student *p;
 printf("There are %d records!\n\n",n);
 
 p = head;
 if(head)
 {
 do
 {
 printf("NO.%d student's score is %d\n",n,p->score);
 p = p->next;
 }while(p);
 
 }
 }
 | 
 |