您的位置:首页 >> 编程开发 >> C/C++ >> 正文
C/C++ RSS
 

malloc函数的用法

http://www.rdxx.com 05年09月13日 23:27 Blog.ChinaUnix.net 我要投稿

关键词: 函数
用到结构、链表

      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 }


 
 
标签: 函数 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站