如何制作这个正确的链接列表

时间:2011-08-09 01:20:08

标签: c

// this is program designed to create Cd data base

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//=============================================
//LINKED LIST USED FOR CREATING THE DATABASE CD
//=============================================
struct CD_type_node
{
   int CDnum;
   char title[20];
   int CDcount;
   struct CD_type_node* next;
}

struct Artist_type_node // to create a linked list of CD's
{
   char Artist_name[20];
   struct CD_type_node* next;
}


int main()
{
   struct CD_type_node* mylist; // this points to the first node of the linked list
   mylist = (struct CD_type_node*)malloc(sizeof(struct CD_type_node));

   free(mylist);
   return 0;
}

我正在尝试创建两个链接列表。一个是CD数据库,另一个是艺术家。其中一个限制是:

2)创建一个Artist_type_node结构,其中包含以下字段:

  • 艺术家姓名
  • 指向CD_type_node的指针,使您可以为CD创建链接列表。

它给我的错误是正确的吗?

它还要求我创建一个包含artist_type_node

类型的100个元素(在main中)的数组

1 个答案:

答案 0 :(得分:1)

您的立即问题是您在两个结构语句的末尾缺少分号。你应该:

struct CD_type_node
{
   int CDnum;
   char title[20];
   int CDcount;
   struct CD_type_node* next;
};

struct Artist_type_node // to create a linked list of CD's
{
   char Artist_name[20];
   struct CD_type_node* next;
};

创建元素数组与创建int xyzzy[42];的整数数组(当然类型除外)没什么区别。使用类似的东西:

struct Artist_type_node artist[100];
相关问题