⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dynlist.c

📁 c版本的
💻 C
字号:
                                         /* Chapter 12 - Program 1 */
main()
{
struct animal {
   char name[25];
   char breed[25];
   int age;
} *pet1, *pet2, *pet3;

   pet1 = (struct animal *)malloc(sizeof(struct animal));
   strcpy(pet1->name,"General");
   strcpy(pet1->breed,"Mixed Breed");
   pet1->age = 1;

   pet2 = pet1;   /* pet2 now points to the above data structure */

   pet1 = (struct animal *)malloc(sizeof(struct animal));
   strcpy(pet1->name,"Frank");
   strcpy(pet1->breed,"Labrador Retriever");
   pet1->age = 3;

   pet3 = (struct animal *)malloc(sizeof(struct animal));
   strcpy(pet3->name,"Krystal");
   strcpy(pet3->breed,"German Shepherd");
   pet3->age = 4;

       /* now print out the data described above */

   printf("%s is a %s, and is %d years old.\n", pet1->name,
           pet1->breed, pet1->age);

   printf("%s is a %s, and is %d years old.\n", pet2->name,
           pet2->breed, pet2->age);

   printf("%s is a %s, and is %d years old.\n", pet3->name,
           pet3->breed, pet3->age);

   pet1 = pet3;   /* pet1 now points to the same structure that
                      pet3 points to                           */
   free(pet3);    /* this frees up one structure               */
   free(pet2);    /* this frees up one more structure          */
/* free(pet1);    this cannot be done, see explanation in text */
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -