1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <stdbool.h> 5 #define SIZE 5 6 7 typedef struct _student{ 8 char *name; 9 int age; 10 short id; 11 double record; 12 } Student; 13 14 Student *initStudent(){ 15 Student *ptrStu = (Student *)malloc(sizeof(Student)); 16 ptrStu->name = (char *)malloc(sizeof(char) * 20); 17 printf("please input student info: "); 18 printf(" name: "); 19 scanf("%s", ptrStu->name); 20 printf("age: "); 21 scanf("%d", &ptrStu->age); 22 printf("id: "); 23 scanf("%d", &ptrStu->id); 24 printf("record: "); 25 scanf("%f", &ptrStu->record); 26 27 return ptrStu; 28 } 29 30 void displayStudent(Student *ptrStu){ 31 printf("The student %s's info: ", ptrStu->name); 32 printf("name: %s ", ptrStu->name); 33 printf("age: %d ", ptrStu->age); 34 printf("id: %d ", ptrStu->id); 35 printf("record: %f ", ptrStu->record); 36 printf(" "); 37 38 return; 39 } 40 41 int main(int argc, char **argv) 42 { 43 Student *arrStu[SIZE]; 44 for(int i = 0; i < SIZE; i++){ 45 arrStu[i] = initStudent(); 46 } 47 for(int i = 0; i < SIZE; i++){ 48 displayStudent(arrStu[i]); 49 } 50 51 return 0; 52 }