malloc函数的用法
作者:Ahaoz.CoM 来源:本站整理 发布时间:2005-11-20 23:39:32 发布人:admin
--------------------------------------------------------------------------------
用到结构、链表
1 #include
2 #include
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 }
阅读(1377) | 评论(0) | 转发(0) |