| 用到结构、链表 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main(void) 5 { 6 struct student 7 { 8 char name[20]; 9 int score; 10 struct student *next; 11 }; 12 typedef struct student s_data; 13 s_data *new_student; 14 new_student = (s_data*) malloc(sizeof(s_data)); 15 if(new_student == NULL) 16 { 17 puts("faild!"); 18 } 19 else 20 { 21 printf("name:"); 22 fgets(new_student->name, 20, stdin); 23 printf("score:"); 24 scanf("%d",&new_student->score); 25 new_student->next = NULL; 26 } 27 printf("name:%s score:%d\n",new_student->name,new_student->score); 28 free(new_student); 29 return 0; 30 } |