1 #include <stdio.h> 2 #include <stdlib.h> 3 4 struct student{ 5 int num; 6 char str[20]; 7 double dec; 8 }; 9 10 void scan(struct student *stu[], int *n){ 11 scanf("%d", n); 12 *stu = (struct student *)malloc(*n * sizeof(struct student)); 13 14 for(int i = 0; i < *n; ++i){ 15 scanf("%d%s%lf", &(*stu)[i].num, (*stu)[i].str, &(*stu)[i].dec); 16 } 17 } 18 19 void print(struct student stu[], int n){ 20 21 printf("%d ", n); 22 for(int i = 0; i < n; ++i){ 23 printf("%d %s %lf ", stu[i].num, stu[i].str, stu[i].dec); 24 } 25 } 26 27 int main(){ 28 int n; 29 struct student *stu; 30 31 scan(&stu, &n); 32 print(stu, n); 33 34 free(stu); 35 return 0; 36 } 37 /* 38 3 39 20 字符串0 20.02 40 21 字符串1 21.12 41 22 字符串2 22.22 42 */