|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
2 #include <malloc.h>
3 #include <stdlib.h>
4
5 #define LEN sizeof(struct student)
6
7 typedef int type_int;
8 typedef float type_float;
9
10 struct student *creat();
11 void print(struct student *);
12
13 struct student
14 {
15 type_int num;
16 type_float score;
17 struct student *next;
18 };
19
20 int main()
21 {
22 struct student *p;
23 p = creat();
24 print(p);
25 }
26 struct student *creat()
27 {
28 int n = 0;
29 struct student *head;
30 struct student *p1, *p2;
31 head = NULL;
32 p1 = p2 = (struct student *)malloc(LEN);
33 scanf("%d", &p1->num);
34 scanf("%f", &p1->score);
35 while(p1->num != 0)
36 {
37 n++;
38 if(n == 1)
39 {
40 head = p1;
41 }
42 else
43 {
44 p2->next = p1;
45 }
46 p2 = p1;
47 p1 = (struct student *)malloc(LEN);
48 scanf("%d", &p1->num);
49 scanf("%f", &p1->score);
50 }
51 p2->next = NULL;
52 return head;
53 }
54
55 void print(struct student *head)
56 {
57 struct student *p;
58 p = head;
59 if(p != NULL)
60 {
61 do
62 {
63 printf("%d %f\n", p->num, p->score);
64 p = p->next;
65 }while(p != NULL);
66 }
67 } |
|