-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct.c
More file actions
73 lines (50 loc) · 1.19 KB
/
struct.c
File metadata and controls
73 lines (50 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <stdlib.h>
#include <malloc/malloc.h>
#define LEN sizeof(struct student)
struct student {
int num;
float score;
struct student *next;
};
void print_1() {
printf("1312312");
}
typedef int inter ;
typedef void (*fun)();
void main() {
// string s1 = "1232132";
// printf("%s\n", s1);
//
// fun p;
// p = print_1;
// p();
// 制作动态链表
int num, i=1;
float score;
struct student students, *p1, *p2;
// p1 = p2 = (struct student *)malloc(LEN);
do {
printf("请输入学号:");
scanf("%d", &num);
printf("请输入成绩:");
scanf("%f", &score);
if (i != 1) {
p1 = (struct student *)malloc(LEN);
p1->num = num;
p1->score = score;
p2->next = p1;
p2 = p1;
} else {
students.num = num;
students.score = score;
p2 = p1 = &students;
}
p1->next = NULL;
i++;
} while (num != 0);
while (students.next != NULL) {
printf("学号:%d,分数:%2.2f\n", students.num, students.score);
students = *students.next;
}
}