1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #define LEN sizeof(struct stu_power) 5 6 struct stu_power 7 { 8 char *stu_name; 9 unsigned int power; 10 }; 11 12 int main () 13 { 14 struct stu_power *head; //head存放 stu_power的首地址 15 16 head = (struct stu_power *) malloc(LEN); 17 18 head->stu_name = (char *) malloc(50); //为避免内存泄露,重新为 char *stu_name 分配一块内存空间 19 20 scanf ("%s %d", head->stu_name, &head->power); 21 22 printf ("%s --> %d\n", head->stu_name, head->power); 23 24 free(head); 25 26 return 0; 27 }